MozillaZine

capture window.alert, confirm from the extension javascript

Talk about add-ons and extension development.
vsrini
 
Posts: 4
Joined: October 5th, 2005, 3:11 pm

Post Posted October 5th, 2005, 3:17 pm

Is there a way I can capture window.alert and window.confirm raised by the documents loaded in the page?

I tried,
window.alert = function(txt) {
// my code here
}

but this works only for code within my extension. How can I extend this to the page that is loaded?

Thanks,
Vinay

asqueella
 
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post Posted October 5th, 2005, 3:30 pm

rewrite content.alert each time a page is loaded.

Ihoss

User avatar
 
Posts: 376
Joined: July 4th, 2004, 11:11 am

Post Posted October 5th, 2005, 4:17 pm


vsrini
 
Posts: 4
Joined: October 5th, 2005, 3:11 pm

Post Posted October 5th, 2005, 4:19 pm

Thanks for the quick reply,

As a test, I tried to do this,

content.alert = function (txt) {
window.document.location = "http://www.google.com";
}

This seemed to have no effect on the document alerts!
I also tried to just suppress the alert by emptying the function, did not help either.

But if i have the same code in the document's <script> tag, it works fine, In extension's code, it doesn't

asqueella
 
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post Posted October 5th, 2005, 4:33 pm

Did you do this in a page load handler?

vsrini
 
Posts: 4
Joined: October 5th, 2005, 3:11 pm

Post Posted October 5th, 2005, 5:09 pm

Yes, i have gBrowser.addProgressListener(myobject) set,

when the page loads, i call myotherobject.pageLoaded(), where I try to rewrite alert for that page.

vsrini
 
Posts: 4
Joined: October 5th, 2005, 3:11 pm

Post Posted October 5th, 2005, 5:13 pm

Also, wanted to know if this is possible, this also does not seem to work.

Code: Select all
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);

var promptServiceAlert = promptService.alert;

// override prompt service alert
promptService.alert = function (parent , dialogTitle, text) {
    promptServiceAlert(parent, dialogTitle + "my custom text : ", text + "append");
}

asqueella
 
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post Posted October 6th, 2005, 2:44 am

Replacing alert function of prompt service certainly isn't going to work. As far as I can see (using the JS Shell of Extension Developer's Extension), replacing content.alert works. So I think you're just doing something wrong.

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 1 guest