Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


running javascript on current page once loaded from a firefox for android add on using -'android,firefox-addon'


running javascript on current page once loaded from a firefox for android add on  using -'android,firefox-addon'

I am wanting to run JavaScript on each and every page that is loaded within the browser. The JavaScript should only be run after the page is loaded and needs to access all elements within the DOM.

I am able to successfully execute the following JavaScript within Scratchpad, although having problems porting it over to my bootstrap.js.

// Use the current content window as the execution context.
// To make properties defined by scripts executing on the page
// available to your sandbox script, use content.wrappedJSObject
// instead.
let context = content;

// Create the Sandbox
let sandbox = Components.utils.Sandbox(context, {
    // Make properties of the context object available via the
    // script's global scope
    sandboxPrototype: context,
    // Wrap objects retrieved from the sandbox in XPCNativeWrappers.
    // This is the default action.
    wantXrays: true
});

// The script that will be executed:
let script = "document.body.style.background = 'red'; alert('test')";

// Evaluate the script:
Components.utils.evalInSandbox(script, sandbox,
                               // The JavaScript version
                               "1.8",
                               // The apparent script filename:
                               "zz-9://plural/zed/alpha",
                               // The apparent script starting line number:
                               42);


Could anyone kindly shed some light as to where exactly the above code needs to be placed within the bootstrap.js?
    

asked Sep 7, 2015 by rajesh
0 votes
3 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...