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?
You need to make a framescript out of it, this is complete example, your script that will execute in the DOM should go into the contentscript.js file: https://github.com/Noitidart/modtools
If you use the addon-sdk, it handles this for you, I prefer not to though thats why my repo linked above does it this way.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments