How to access webpage data from Firefox extension?

I managed to get a custom very basic extension working in Firefox.

What I want to do next:

  • Check if the user is on the desired web page.
  • If yes: check the page on each postback for a hidden element containing a string
  • If found: launch an external application with a string parameter

I have experience with javascript on web pages, but I don’t know how to register my script to run on every web page open in firefox, and how to access elements on the page.

Tips on where to start will be appreciated ...

EDIT: I figured out how to run my code on every page:

addEventListener("DOMContentLoaded", doSomething, false);

EDIT2: I could access the page data using event.originalTarget in the handler and run the applications using Component.interfaces.nsIProcess

+2
source share
1 answer

So, you have to bypass the DOM and launch an external program.

Your DOM bypass can be done in many ways. However, here just take

var inputs = document.getElementsByTagName("input");
for (var idx=0; idx<inputs.length; idx++){
    var tp = inputs[idx].attributes['type'].value
    console.log(tp);
    if (tp == 'hidden'){
       // grab your text at here and launch the app.
    }
}

Launching an external application according to this post

var file = Components.classes["@mozilla.org/file/local;1"]
                     .createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("c:\\myapp.exe");
file.launch();
+2
source

Source: https://habr.com/ru/post/1722558/


All Articles