Running JavaScript on current page once loaded from a Firefox for Android add-on

Brandon Young

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?

Noitidart

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is there a way I can create a custom toolbar button for Firefox 26 that is written in javascript and has access to the currently loaded page?

From Dev

Android ViewPager Inside Fragment Loaded Only Once

From Dev

How to get current page loaded url from iframe

From Dev

how to format web page content loaded from javascript?

From Dev

Is it possible to add a component loaded from an FXML file more than once without rereading it?

From Dev

Trying to prevent Javascript from running on page load

From Dev

Unable to execute javascript loaded from external html page

From Dev

Preventing Firefox add-on first page from showing up

From Dev

Accessing the DOM from a Firefox for Android add-on

From Dev

Running Firefox Add-on on Android using jpm-mobile

From Dev

JavaScript Not Running On PHP Loaded HTML

From Dev

Reloading a WebView with a JavaScript call from a loaded web page

From Dev

Not to reload the fragment once loaded-ANDROID

From Dev

Android get current running application package name from service

From Dev

After page loaded, reload page once after 2 second delay

From Dev

Restore a deleted CSS from loaded page on localhost in firefox

From Dev

Asp page not running in firefox or chrome

From Dev

Cannot execute javascript code from loaded page

From Dev

Is there a way I can create a custom toolbar button for Firefox 26 that is written in javascript and has access to the currently loaded page?

From Dev

javascript called but not loaded on page

From Dev

Failing at attempt to reference text within a page using xpath and javascript from a custom Firefox extension/add-on

From Dev

Javascript Not Executing When Web Page Loaded from Cache

From Dev

Is it possible to start a Windows process from Javascript running in a web page in Firefox or IE

From Dev

What happens to injected javascript when new page is loaded in android webview?

From Dev

Javascript running twice instead of once

From Dev

Calling add-on from web page in new multiprocess Firefox

From Dev

I want the Page to be Loaded Only once

From Dev

How do we check if the current page is loaded from the sidemenu in ionic 2

From Dev

javascript code only work once, when page is loaded

Related Related

  1. 1

    Is there a way I can create a custom toolbar button for Firefox 26 that is written in javascript and has access to the currently loaded page?

  2. 2

    Android ViewPager Inside Fragment Loaded Only Once

  3. 3

    How to get current page loaded url from iframe

  4. 4

    how to format web page content loaded from javascript?

  5. 5

    Is it possible to add a component loaded from an FXML file more than once without rereading it?

  6. 6

    Trying to prevent Javascript from running on page load

  7. 7

    Unable to execute javascript loaded from external html page

  8. 8

    Preventing Firefox add-on first page from showing up

  9. 9

    Accessing the DOM from a Firefox for Android add-on

  10. 10

    Running Firefox Add-on on Android using jpm-mobile

  11. 11

    JavaScript Not Running On PHP Loaded HTML

  12. 12

    Reloading a WebView with a JavaScript call from a loaded web page

  13. 13

    Not to reload the fragment once loaded-ANDROID

  14. 14

    Android get current running application package name from service

  15. 15

    After page loaded, reload page once after 2 second delay

  16. 16

    Restore a deleted CSS from loaded page on localhost in firefox

  17. 17

    Asp page not running in firefox or chrome

  18. 18

    Cannot execute javascript code from loaded page

  19. 19

    Is there a way I can create a custom toolbar button for Firefox 26 that is written in javascript and has access to the currently loaded page?

  20. 20

    javascript called but not loaded on page

  21. 21

    Failing at attempt to reference text within a page using xpath and javascript from a custom Firefox extension/add-on

  22. 22

    Javascript Not Executing When Web Page Loaded from Cache

  23. 23

    Is it possible to start a Windows process from Javascript running in a web page in Firefox or IE

  24. 24

    What happens to injected javascript when new page is loaded in android webview?

  25. 25

    Javascript running twice instead of once

  26. 26

    Calling add-on from web page in new multiprocess Firefox

  27. 27

    I want the Page to be Loaded Only once

  28. 28

    How do we check if the current page is loaded from the sidemenu in ionic 2

  29. 29

    javascript code only work once, when page is loaded

HotTag

Archive