Disable JavaScript Alerts GeckoFX C# - javascript

I'm trying to disable JavaScript alert in GeckoFX-33 + xulrunner 33 ( winforms c# ) but I can't find a solution. I check the example codes, source code but I just can't find something that blocks the alert out. I searched in about:config as well without success.
Anybody knows where I could find a reference at last ?

In prior versions, you could do
webBrowser.JavascriptError += (sender, error) => {
// do something
}
However according to issue 7 on geckofx 33, there's some work that needs to be done to support the new debugging interface:
the geckofx service jsdIDebuggerService was removed from firefox 33. the JavascriptError event implementation used this service. So the JavascriptError event handler needs to be reimplemented using firefox new debugging interface.

geckoWebBrowser1.JavascriptError += (sender, error) =>
{
GeckoWebBrowser browser = geckoWebBrowser1;
string text = "window.alert = function(){};";
using (AutoJSContext context = new AutoJSContext(browser.Window.JSContext))
{
string result;
//toolStripLabel1.Text = "was is loaded?";
context.EvaluateScript(text, (nsISupports)browser.Window.DomWindow, out result);
}
};
Here is the final code for Gecko 29.

Related

Internet Explorer - Syntax Error - AngularJS

I am working on a web site using angularJS. The project is made on Visual Studio so the server is IIS.
When using Chrome, everything is working fine. But my boss wants also this site to work fine with Internet Explorer 11, in case of some clients are only using this browser.
The problem is that i have an error at an unexpected place when is use IE, for example :
Syntax Error : Caractère Incorrect ( that's french, it means Invalid character )
at getConnectedUser (http://localhost:54579/mypath/myfile.js:121:13)*
And if i open this file at line 121
vm.connectedUser = JSON.parse($cookies.get("userLogged"))
and the 13th character is the v from vm ( since i have some tabs )
the wole function is :
function getConnectedUser() {
vm.connectedUser = JSON.parse($cookies.get("userLogged"))
}
Which is quite normal according to me...
I don't know how to solve this, since the error does not seem to come from the code but from the interpretation of my browser.
I have read that some keywords were not supported to declare variables, like const. I use "let" to declare my variables and it is supported by IE 11 according to this site
EDIT : i also use "var" ( for example : var vm = this )
It would be very helpful if you have some ideas to find a solution.
Thanks for reading,
Sonny
So
I tried to apply what you guys asked, here is what i've got :
The problem actually comes from my cookies, IE can't read it correctly, I get undefined when trying to log my cookie's type, instead of getting "string".
So i went to a different part of the projet, where this cookie is created.
I try to log the cookie just after it is created so it can't be alterated:
var myObject = { "value" : "sonny" }
var stringified = JSON.stringify(myObject) // myObject is validated by jsonlint.com
try {
$cookies.put("userLogged", stringified, {})
console.log("ok")
}
catch (error) {
console.log(error)
}
// i got "ok" in logs , the try part is successful
console.log("fresh cookie : ")
console.log(typeof $cookies.get("userLogged"))
// On Chrome Console : string
// On Ie Console : undefined
console.log(typeof JSON.parse($cookies.get("userLogged")))
// On Chrome Console : object
// On Ie Console: Not logged , i have the Syntax Error Message
So the problem seems to be that IE can't read the cookie i just set before.
Using IE developers tools , i can see the cookie line :
Value : %7B%22value%22%3A%22sonny%22%7D
each special character ( '{', '"' and '}' ) is replaced by "%7B" , "%22" and "%7D"... It is exactly the same with chrome developers tools so i don't think it should be a problem.
Can IE actually read cookies using angular and ngCookies ?
As everyone mentioned in comments.
It is difficult to solve the issue with information provided.
So the best option could be using IE developer tools and debug your application.
Here is how I can troubleshoot the issue.
function getConnectedUser() {
// forces browser to stop at below line
debugger;
var loginInfo = $cookies.get("userLogged"); //put a debug point
// check for loginInfo existence and typeof loginInfo should be string
if (loginInfo && typeof loginInfo === 'string'){
vm.connectedUser = JSON.parse(loginInfo);
}
}
Put a break point in the getConnectedUser function
Check the value of $cookies.get("userLogged"), whether it is returning data or not
yes => check the type of data. It must be a valid JSON string format.
No => do the corresponding actions

JavaScript Methods Not Executing Consistently In Mobile Safari vs. Android Chrome

I have a method in JavaScript that looks as follows:
function onAction() {
getValue1();
getValue2();
getValue3();
}
When I call onAction() I see two different behaviors between Mobile Safari and Android Chrome. In Safari, I get the values for all three methods. On Android Chrome, I only get the value of the last method. It doesn't matter which one is last. I suspected it may be an execution timing issue and attempted the following:
function onAction() {
new Promise(function(resolve,reject) {
resolve(1);
})
.then(function() {
getValue1();
})
.then(function() {
getValue2();
})
.then(function() {
getValue3();
});
}
Again, it works fine in Mobile Safari, but not Android Chrome.
I'm sure I'm missing something obvious, but it's eluding me. If it matters, the getValue* functions are used to get values via each platform's mechanism for Native Code->JavaScript bridging.
Any help is appreciated. Please let me know if I can supply any more information.
Regards,
Rob
**Additional Info **
The getValueX functions don't return any values. They trigger values to be pushed over to the native wrapper:
function getReaderSDKVersion() {
var message = {'action' : MPDataEnum.SDKVersion};
raiseMessage(message);
}
function raiseMessage(message) {
if (isPlatformiOS()) {
window.webkit.messageHandlers.interOp.postMessage(message);
} else {
var url = "mpcard://runMethod#" + JSON.stringify(message);
window.location.href = url;
}
}
The issue is answered here:
Triggering shouldStartLoadWithRequest with multiple window.location.href calls
Whereas this was an issue in most browsers, it doesn't appear to affect Mobile Safari now.

Get table row object inside javascript function - DHTMLX

We are doing cross browser compatibility for an application which was built over 8 years ago. The app works only in IE. Now we are making it work in Chrome too. The application had used 1.5 version of DHTMLX. Now we have replaced it to version 3.5. After upgradation to 3.5, we are having some issues. At some places, we are getting NULL values in Chrome when debugged in the console.
For example, we have this below function. On click of a DHTMLX grid checkbox, this function is called.
var glbGroupId=null;
function setRowCellVals(){
if(arguments[0]!=null){
radioFlag = true;
src=$(arguments[0]);
if(!glbCheckAction){
if(src.childNodes[0].childNodes[0].checked){
src.childNodes[0].childNodes[0].checked=false;
}else{
src.childNodes[0].childNodes[0].checked=true;
}
}
glbCheckAction = false;
glbGroupId=src.childNodes[0].childNodes[0].value;
document.manageKpiGroupForm.parent_GId.value = src.id;
document.manageKpiGroupForm.parent_Gname.value = src.childNodes[1].innerHTML;
document.manageKpiGroupForm.parent_mId.value = $F('moduleCmb');
document.manageKpiGroupForm.parent_mName.value = src.childNodes[3].innerHTML;
document.manageKpiGroupForm.parent_gDesc.value = src.childNodes[4].innerHTML;
moduleRowId=arguments[0];
return true;
}
}
In Chrome, the src is being rendered as NULL. We checked the same function in IE, in another copy which has the older version of DHTMLX, the src value comes as [object DispHTMLTableRow] in the IE console. Any idea how to resolve this?
Thanks.
Unfortunately, the reason of the issue cannot be found with the provided code.
Please provide with a more detailed sample or with the link to the demo, where the problem can be reconstructed.

javascript. formatting console.log

I´m working on a big angular.js project.
Now, I´ve to profile some pages about the performance.
With the console.log of the project I´m looking for the performance problems.
I miss if console.log can output the current time (yes, I know in Chrome you can set up).
Is there a way (like in log4java) to format the output?
Thanks in advance,
Be careful, the console object should not be activated in production mainly because it can breaks the code for some users (for example IE8 or less users).
But if you want to test on a tool that you know, you can use the Web API interface which provides some useful method on this object:
https://developer.mozilla.org/en-US/docs/Web/API/Console
(This doc is from the Mozilla Developer Network (MDN) and therefore mainly applies to Firefox, but at the end of that page you can find links to the corresponding docs for the IE, Chrome and Safari DevTools as well as Firebug).
For example, you can use the time() method for your use case:
console.time("answer time");
// ... some other code
console.timeEnd("answer time");
Outputs something like this:
You could try something like this:
console = window.console ? console : {};
native_log = console.log;
window.console.log = function myConsole() {
// Cannot log if console.log is not present natively,
// so fail silently (in IE without debugger opened)
if (!native_log)
return;
var args = Array.prototype.slice.call(arguments);
args.unshift(new Date());
native_log.apply(console, args);
}
console.log('hello'); // Date 2014-12-02T14:14:50.138Z "hello"
Of course, you would not let the new Date() as is, but it gives you the idea.

Why does ExternalInterface breaks when I pass parameter with JSON like string?

I have a very odd problem with Flash 10 and ExternalInterface. I am currently using a homemade bridge to use RTMFP with Javascript and whenever I try to pass data that contains JSON, I get a wierd Javascript error that comes from Flash :
missing ) after argument list
try { __flash__toXML(Flash.Utilities.A..."")) ; } catch (e) { "<undefined/>"; }
It's impossible to get more information since this come from Flash and it's not bound to any Javascript file.
To reproduce this problem you can use this script :
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.external.ExternalInterface;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
var test:String;
test = "\"\\\"\"";
ExternalInterface.call("console.log", test);
}
}
}
What can I do to avoid this problem and is it a known problem ?
This is apparently a known issue and it doesn't seems like Adobe is going to fix it anytime soon.
I found a detailled explaination of this problem and basicly the issue seems to be that Flash doesn't handle the \ and the & properly which can lead to javascript error or data corruption during the transfer from Flash to javascript.
What Flash attempts to do when you transfer data from Flash to JS is to execute the following thing :
try {
__flash__toXML(yourJavascriptFunction("[DATA]")) ;
} catch (e) { "<undefined/>"; }
The problem is that it puts your data raw and it doesn't escape the backslash at all. If your string contains only \ and you want to call console.log on it, it will try to do the following thing :
try {
__flash__toXML(console.log("\")) ;
} catch (e) { "<undefined/>"; }
As you can see this is invalid javascript. It will throws an error in your Javascript console and it will never call console.log.
The solution is to either ducktape Flash behavior or do some nasty hack to get around it.
To ducktape Flash buggyness you can escape the blackslash before you transfer them. This solution will work for now, but when Flash will fix it (most probably not in a near future, if you consider that this bug is known for more than 4 years), it will break your application.
The other possibility is to url encode the character that Flash doesn't handle well (\, ", &) and to decode them on the other side.
Flash :
data = data.split("%").join("%25")
.split("\\").join("%5c")
.split("\"").join("%22")
.split("&").join("%26");
Javascript :
data = data.replace(/%22/g, "\"")
.replace(/%5c/g, "\\")
.replace(/%26/g, "&")
.replace(/%25/g, "%");
It's ugly, but it works.
Admittedly this wouldn't work directly for output to the console in Firebug, but for most other applications (i.e. sending a potentially 'invalid' string to Javascript), escape and unescape should work just fine:
AS3:
var testString:String = "\"\\\"\"";
ExternalInterface.call("showString", escape(testString));
And then in Javascript:
function showString(msg) {
console.log(unescape(msg));
document.getElementById('messagebox').innerHTML = unescape(msg);
}
<div id="messagebox"></div>

Categories

Resources