How to override JS function from a firefox extension?

Posted by BruceBerry on Stack Overflow See other posts from Stack Overflow or by BruceBerry
Published on 2010-06-01T04:47:22Z Indexed on 2010/06/01 4:53 UTC
Read the original article Hit count: 207

Hello,

I am trying to intercept calls to document.write for all pages. Setting up the interception inside the page by injecting a script like

function overrideDocWrite() {
 alert("Override called");
 document.write = function(w) {
  return function(s) {
   alert("special dom");
   w.call(this, wrapString(s));
  };
 }(document.write);
 alert("Override finished");
}

is easy and works, but i would like my extension to setup the interception for each document object from inside the extension. I couldn't find a way to do this. I tried to listen for the "load" event and set up the interception there but it also fails. How do I hook calls to doc.write from an extension?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about firefox-extension