Organizational Research By

Surprising Reserch 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 = " = 'red'; alert('test')";

// Evaluate the script:
Components.utils.evalInSandbox(script, sandbox,
                               // The JavaScript version
                               // The apparent script filename:
                               // The apparent script starting line number:

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

Related Hot Questions

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.