I have no idea what is going wrong here. When I run this code on a website, it doesn't give an error.
It is meant to be ran from a bookmark in a browser to inject a script into a website, but I'm not getting the prompts to show.
var s = document.createElement('script');
s.type='text/javascript';
document.body.appendChild(s);
if confirm('Press OK to enter a url to the script/nPress Cancel to enter code directly')
{
s.src=prompt('Enter the url to the script file (javascript only):');
} else {
s.innerhtml=prompt('Enter code to inject (javascript only):');
}
void(0);
This is the version of the code that will be ran from a bookmark.
javascript:var s = document.createElement('script');s.type='text/javascript';document.body.appendChild(s);s.innerhtml=prompt('Enter code to inject (javascript only):');
You need to wrap if conditions in parentheses, eg
if (confirm('Press OK to enter a url to the script/nPress Cancel to enter code directly'))
The error I got with your original code was
SyntaxError: Unexpected identifier
Related
We can't get the url query 'code' to our google script.
1
This discord documentation https://discordapp.com/developers/docs/topics/oauth2
shows that we get an redirect url with a query names 'code' back.
Like:
https://nicememe.website/?code=NhhvTDYsFcdgNLnnLijcl7Ku7bEEeee
2
we get this url (my version) and now we want to call with that redirect a google app script. Something like:
https://script.google.com/macros/s/AKfycbyyt9-FiVv0zXOr8p8pMfojwEs2AXvBftVN1xdWeU3UQ1xgURD/exec?
code=NhhvTDYsFcdgNLnnLijcl7Ku7bEEeeD
3
How we want to handle this 'code=NhhvTDYsFcdgNLnnLijcl7Ku7bEEeeD' in the app script.
We already tried: release that script as an app. so we get the redirect url. its the part at the url that redirect us to the google script.
But if we do this, we have a problem: if we release the script as an app, we have to call the function doGet(e){}
In the script an we have to return something.
function doGet(e) {
code = ScriptApp.getService().getUrl();
Logger.log(code);
return ContentService.createTextOutput(code);
}
at the logger in google script I only get this url.
https://script.google.com/macros/s/AKfycbyyt9-FiVv0zXOr8p8pMfojwEs2AXvBftVN1xdWeU3UQ1xgUDD/exec
But if we break the program with some error, I get the right url in the url bar at the top. So why we get the right redirect url, but some little seps later we only have the normal url (without code) left?
and how i can use console.log? Normally in js i can open google DevTools an get the console log. but at google script that doesn't work :(
Thanks for any help <3
Got it!
function doGet(e){
var codeStr = e.queryString;
var codeArray = codeStr.split("=");
var code = codeArray[1];
Logger.log(code);
return ContentService.createTextOutput(code);
}
I am trying to login to a website using AjaxForm. I managed to retine the forms and reach the xpath of the desired button though when I call #click I get this error:
EcmaError: lineNumber=[193] column=[0] lineSource=[<no source>] name=[ReferenceError] sourceName=[script in https://test.paypo.com/Account/Login?ReturnUrl=%2FHome%2FStart from (177, 32) to (221, 10)]
message=[ReferenceError: "Paypo" is not defined.
(script in https://test.paypo.com/Account/Login?ReturnUrl=%2FHome%2FStart from (177, 32) to (221, 10)#193)]
com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "Paypo" is not defined. (script in https://test.paypo.com/Account/Login?ReturnUrl=%2FHome%2FStart from (177, 32) to (221, 10)#193)
I am honestly clueless on how to get around this... important note is that I have no access to the source of the website, the actual website logging works perfectly fine.
I've tried using any kind of BrowserVersion and different HtmlUnit versions...
Current code:
final HtmlPage thePage = ((HtmlPage) page);
final HtmlButtonInput button = (HtmlButtonInput) thePage.getByXPath("//input[#type='button']").get(0);
webClient.getOptions().setThrowExceptionOnScriptError(true);
final HtmlPage newPage = button.click();
Error araises when #click is called!
Any clue? Please!
Ok have done a short check with this code:
final String url = "https://test.paypo.com/Account/Login?ReturnUrl=%2FHome%2FStart";
try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_60)) {
HtmlPage page = webClient.getPage(url);
}
Running this produces a bunch of errors; the first one is
com.gargoylesoftware.htmlunit.ScriptException: identifier is a reserved word: class (https://test.paypo.com/bundles/SharedJS?v=qrYYsvxJCv4nRnx8xzi1sMLBQPQlIPteJjoj8eCO1go1#7)
What does this mean?
The page includes some js code from the url https://test.paypo.com/bundles/SharedJS?v=qrYYsvxJCv4nRnx8xzi1sMLBQPQlIPteJjoj8eCO1go1 and there is a problem with this code. In detail the code uses the javascript 'class' language feature and HtmlUnit (in the end Rhino) does not support this syntax in the current version
Because of this the javascript from this external resource is not 'compilable' and thereof not available for the other javascript on that page
And finally this leads to the error you are facing.
Hello,
I am trying to test error supression on Sharepoint but I am having some trouble.
This is my process:
On a relatively plain website (all it contains is a colored-in div), I added this script:
<script>
var x[] = 0;
var err = 10/x;
alert(err);
</script>
When setting my Outlook homepage to this site, I see this error:
I also have the following script, which suppresses this message (when adding this to my code, the error message doesn't appear):
<script type="text/javascript">
window.onerror = function(message, url, lineNumber) {
// code to execute on an error
return true; // prevents browser error messages
};
</script>
I want to test this script out on my Sharepoint site, but when I embed the above, error-inducing code onto my Sharepoint homepage and open the page in Outlook, I am not seeing any error messages.
I added the code in the following ways:
1 - Page > Edit > Edit Source > Added the code to the top
2 - Page > Edit > Embed Code > Added the code to various areas of the page
Neither of these methods worked, and the first one actually produced a message telling me that I should use the embed function, which also doesn't seem to work!
I need to generate this error from the Sharepoint page so that I can check **whether the error-suppressing script actually does what it's supposed to. Can **anyone think of what may be going wrong here?
Any help is much appreciated!
This is apparently a known issue in Sharepoint, and can be resolved by using the following function:
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
//your code goes here...
});
For the purposes of the above test, I was able to generate an error with the following:
<script language='javascript'>
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
var x[] = 0;
var err = 10/x;
alert(err);
});
</script>
And adding the below suppressed the errors:
<script language='javascript'>
window.onerror = function(message, url, lineNumber) {
return true;
};
</script>
Note that this only worked for me after adding the 2 bits of code in their own, seperate <script> tags. I also had to add language='javascript' to the tags before it would work.
I added the code by embedding some new code, and adding both of the script tags to that web part. Because I was able to produce the error message, I was also able to prove that the error-suppression method worked.
I was asked to add this code to my pitch pages by the vendor I sell through:
<script>
(function() {
var p = '/?vendor=2knowmysel&time=' + new Date().getTime();
var cb = document.createElement('script'); cb.type = 'text/javascript';
cb.src = '//header.clickbank.net' + p;
document.getElementsByTagName('head')[0].appendChild(cb);
})();
</script>
The code should let the page load within a header that has a red logo by clickbank. When I added the code in the head section nothing happened.
Next I tried to isolate the problem by posting on a blank html page (away from drupal) which is http://www.2knowmyself.com/testpage.htm.
But the frame doesn't show up.
What's wrong in here? Given clickbank claim the code is perfect.
Here's what your code does:
<script>
// the following line creates an anonymous immediately-invoked function
(function() {
// this will return a string named 'p', which contains the vendors ID and current time
var p = '/?vendor=2knowmysel&time=' + new Date().getTime();
// this creates a new 'script' tag for HTML, name it 'cb', and tells the code it's for JavaScript
var cb = document.createElement('script'); cb.type = 'text/javascript';
// this will take a url with the address and the query string, which you named 'p' earlier, and set it as the source for 'cb'
cb.src = '//header.clickbank.net' + p;
// now you'll insert 'cb' to the HTML, so it'll load the JavaScript file into it
document.getElementsByTagName('head')[0].appendChild(cb);
// the function won't run automatically upon declaration, so you use parenthesis to tell it to run
})();
</script>
Summing it up, it bassically sends the vendor's ID and current time to the given server, and expects a JavaScript file in return from it; it'll then load this file into your HTML document.
Currently, it seems not to be working because this server is getting the information from your page but not sending the JavaScript file back to it. When they adjust it to answer with the right file, you'll see it run accordingly.
EDIT: (to answer your Final Question)
Up to this point, I can see that their server isn't sending the expected JS file back at your page, so it doesn't work. If you want to check this by yourself, please use a JS debugger or a network monitor in your browser (most of the modern webbrowsers come with these built-in, try pressing F12 then reloading the page).
If you want to check whether iframes work on your server, you may contact its administrator or try to embed an iframe in the page yourself. Paste the following code into the document. If you see SO homepage, it works. Otherwise, it'll show nothing. If you see Your browser does not support iframes., then you might have to update your web browser and check it again.
<iframe src="http://stackoverflow.com" width="300" height="300">
<p>Your browser does not support iframes.</p>
</iframe>
I am getting the value "msg" from the page http://www.kimi007.freeiz.com/frame.html with the following code (address must be in the address bar and then you hit 'enter', thus getting the alert message "success!"):
javascript:
(function()
{
var%20s=document.createElement("script");
s.setAttribute("type","text/javascript");
s.setAttribute("src","http://www.kimi007.freeiz.com/java.js");
document.getElementsByTagName("head")[0].appendChild(s);
}
)()
The above has these two lines in the .js file:
var capForm = document.getElementById('form').elements[0].value;
alert('' + capForm + '');
I have no problems up to this stage. However I want to put "frame.html" in an iFrame like this:
http://www.kimi007.freeiz.com/test.html
and have my Java code work so I can get the same "success!" message from within the iFrame. Any ideas on how to do this?
Thanks.
try the following code, might do the trick:
top.frames[name_of_the_frame].some_function()