WebBrowser InvokeScript "eval" bug - javascript

So I'm trying to run javascript code on website through my WebBrowser in console application but I came across weird bug. This is my code:
object[] mathArgs = { "javascript:setTimeout('__doPostBack(\'someID\',\'\')', 0)" };
mainWebBrowser.Document.InvokeScript("eval", mathArgs);
and after this I receive:
"There was an error in the script on this page:
Line: 1
Char: 1
Expected char ')'
Code: 0"
Funny thing is it works well in WinForms project, there is problem in console app. Am I missing something? Additionally, it's code that works on page I work on.

If your code work without any problem use the "ScriptErrorsSuppressed" property to ignore JS errors :
WebBrowser mainWebBrowser = new WebBrowser {ScriptErrorsSuppressed = true};
// Navigation code gose here
object[] mathArgs = { "javascript:setTimeout('__doPostBack(\'someID\',\'\')', 0)" };
mainWebBrowser?.Document?.InvokeScript("eval", mathArgs);

Related

SteemJS not working in Firefox/IE

I have a problem with connecting Steem using SteemJs https://github.com/adcpm/steem
Problem appears only on firefox browser, but Chrome Works correctly.
Our app is coded in Yii2 and JavaScript,
which works fully in front-end
<script src="//cdn.steemjs.com/lib/latest/steem.min.js"></script>
<script>
steem.broadcast.comment('5K8eZVEAMkfejyHxeQJ9R4wvrXowwz7kcxcTVwFGpeGq1x2iKRb',
'',
‘test',
'sci',
'this-is-a-test-article-2',
'this is a test article2',
'test',
'',
function(err, result) {
console.log(err, result);
});
Problem in the following process:
When running request to blockchain , it return null in Chrome.
Null is mean ok! so everything is fine
But when running on Firefox error occures:
Error: 3030000 tx_missing_posting_auth: missing required posting authority
Missing Posting Authority sci
…..
{"ops":[["comment", {"parent_author":"","parent_permlink":"test","author":"sci","permlink":"this-is-a-test-article-2","title":"this is a test article2","body":"test","json_metadata":"\"\""}]],"sigs": ["STM7x7kJhdKzu7gie8gPg5uUDNmLjbcXx7ek2H8UtKxH8qub3V2ut"]}
th_a transaction.cpp:172 verify_authority
Sigs here - is always different,but should be same and must be equal to public key from private: GLS8MfcHZyYioPBsmoYp8AZf4mbwZdsarunFRvuWUySqb3nwPeRwb.
In chrome it is working right key.
This is browser-compatibility problem, or browser feature problem
Please help identify a problem, and possible we can patch it or overcome in another way.
npm install adcpm/steem#dev
Just build it from develop branch and problem will solved. In lib folder you can find steem.min.js.

FireFoxDriver JavaScript errors does not show in FireFox browser

I'm using the following code to capture JavaScript errors when running Selenium tests:
public static void AssertNoJavaScriptErrorsInLog(this RemoteWebDriver driver)
{
var errorStrings = new List<string> { "SyntaxError", "EvalError", "ReferenceError", "RangeError", "TypeError", "URIError" };
var jsErrors = driver.Manage().Logs.GetLog(LogType.Browser).Where(x => errorStrings.Any(e => x.Message.Contains(e))).ToList();
if (jsErrors.Any())
{
Assert.Fail("JavaScript error(s):" + Environment.NewLine + jsErrors.Aggregate("", (s, entry) => s + entry.Message + Environment.NewLine));
}
}
One of my tests intermittently reports an error:
Assert.Fail failed. JavaScript error(s):
TypeError: doc.documentElement is null
TypeError: doc.documentElement is null
Trying to locate the error I look in the console of the FireFox browser which just ran the failed tests, but it's empty!
Why can't I see the JavaScript error in the browser console?
You might be experiencing the following fresh selenium issue:
Some new browser logs are not captured
As a workaround, consider downgrading selenium to 2.52.
Also, from time to time there are compatibility issues between selenium and firefox with a wide range of symptoms - play around with firefox versions (you can download older versions here) and see if you still cannot catch the js error on the console.

terminateAppHandler [base.js] Line 9357 Script

I am developing a windows 8 application. After generating a page on the app (I copied the code from win js (http://try.buildwinjs.com/#listview:gridlayout)) always an error occurs:
terminateAppHandler [base.js] Line 9357 Script
The code that generates this error is:
var terminateAppHandler = function (data) {
debugger;
MSApp.terminateApp(data);
};
I don't know what is meaning of the error it self, however with other pages which also use win js doenst happen.
Any idea why?

addthis_widget.js throwing Cannot read property '_pmh' of null error on Android and Chrome

I am using a JavaScript error logging tool to log any JavaScript errors on my mobile site and I am seeing a large number (22,000 in under a month) of this error:
Uncaught TypeError: Cannot read property '_pmh' of null
I can see from the addthis_widget.js code that it is originating from that script.
I can also tell that it only affects mobile Android and Google Chrome browsers, these in particular:
Android 4, Android 4.1, Android 4.2, Chrome 11, Chrome 18, Chrome 25, Chrome 26, Chrome 27, Chrome Mobile 18, Chrome Mobile 25, Chrome Mobile 26
I am using the following external JavaScript include:
http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4b6adff375a64db9
and have the following configuration object set:
<script type="text/javascript">
var addthis_config = {
data_ga_property: 'UA-18721873-1', // real GA profile hidden for privacy purposes
data_ga_social: true
};
</script>
Is there anything I can do to prevent this error from occuring so many times on these browsers?
I have located the cause of this issue and it is down the following code.
if (window.addthis) {
window.addthis = null;
window._adr = null;
window._atc = null;
window._atd = null;
window._ate = null;
window._atr = null;
window._atw = null;
}
This was an attempt to cleanup the objects lying around when moving between pages dynamically to prevent memory issues.
addThis now provide support for this problem, their support department sent me the following link:
http://www.addthis.com/blog/2013/05/07/a-brief-history-of-using-addthis-dynamically/#.Uklx4RCKyas
and the following explanation/information:
Along with other information from my peers and such, I've come up with
the proper code which should be executed when moving from virtual page
to virtual page such as in your mobile application. Rather than
nulling any of the AddThis related objects, they must be left alone.
When the page URL or Title (or any other AddThis configuration option)
that you want to be used by our buttons changes, you should execute
our method:
addthis.update(type, key, value)
It takes the three parameters: type, key, value.
Type is either "share" or "config". The key is the same key you would
set according to our API documentation. What you likely need to know
are just the two keys: "url" and "title". The value is of course the
value you want those options to have.
After you have updated all of the options you need to update using
that method, you need to invoke this method:
addthis.toolbox(cssSelector)
The cssSelector is usually going to be ".addthis_toolbox" but if for
some reason you don't want to refresh all of your toolboxes, you can
be more specific about it.
Once you have made those changes to your code, I believe that our
tools will work properly for you and that there will be no more "null
object" related javascript errors.
You can look at this JSFiddle to see an example of dynamically
changing content: http://jsfiddle.net/j5addthis/r6Utv/
I'm having the same issue, but it appears that there was, at one point, a fix to your specific case above by simply upgrading the script that you're using from addthis to version 3.0 by changing this:
http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4b6adff375a64db9
To this:
http://s7.addthis.com/js/300/addthis_widget.js#username=xa-4b6adff375a64db9
Read more here: http://support.addthis.com/customer/portal/questions/1021465-addthis-widget-js-throwing-cannot-read-property-pmh-of-null-error-on-android-and-chrome
Note though, as I mentioned above, my issue continues to persist even with version 3.0 despite the AddThis help desk stating that should work.

Javascript error in ASP.NET caused by changing from Cassini development server to IIS 7.5 express

I have recently changed from using the cassini development server to IIS 7.5 express, and have found that on some pages my javascript is throwing 'Object doesn't support this property or method' exceptions.
All the pages share the same masterpage which loads all the plugins, and when debugging in the browser the scripts seem to be available.
One particular example is
$(document).ready(function () {
var dlg = $('#<%=PanelAddToList.ClientID%>').dialog({ autoOpen: false, modal: true });
// $('#<%=PanelAddToList.ClientID%> .List-Add').click(function () { __doPostBack('<%=BtnAddToList.UniqueID%>', ''); });
$('#<%=PanelAddToList.ClientID%> .dialog-button-cancel').click(function () { $('#<%=PanelAddToList.ClientID%>').dialog('close'); });
dlg.parent().appendTo(jQuery("form:first"));
});
This is contained in a usercontrol which has PanelAddToList in it. This control works on some pages using IIS but on others it will cause an exception on the 'var dlg =' ... line.
If i switch back to using cassini it all works normally.
Any help would be appreciated, thank you
check if jquery load before not because this type of error occur when they did not find any object.
i think in you case dialog have some error, page can't find dialog method or arguments..

Categories