How to access firefox extension variable from current document / window

My firefox extension has a myExt object.

myExt = { request: function(){ //adds dynamic script element to the current webpage head tag }, callback: function(json) { //do something with this } }; 

myExt.request adds a dynamically added script element to the server that returns json, I want json to be sent to myExt.callback, which exists in my js code extension.

from my extension

 //from my extension, i add a script element myExt.request(); 

server pings back to web page

 //from server i get the following response myExt.callback ( {"some":"json"}) ; //but the window doesnt find a reference to myExt 

How do I link to myExt variable from a webpage?

+4
source share
2 answers

Firefox extensions run JavaScript with high privilege (chrome) and have full browser access. JavaScript code from a web page launches unprivileged JavaScript and, among other things, cannot link to or directly interact with privileged JavaScript.

In general, you should be very careful when your extension code interacts with code coming from websites so as not to open a security hole that would allow an attacker to execute JavaScript with chrome privileges.

Here you can find additional information, including code snippets, if you need to exchange data between privileged and unprivileged JavaScript:

https://developer.mozilla.org/en/Security_best_practices_in_extensions

+5
source

See also this link for exchanging data between privileged and unprivileged JavaScript:

https://developer.mozilla.org/en/Code_snippets/Interaction_between_privileged_and_non-privileged_pages

+5
source

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


All Articles