my firefox extension has an object myExt .
myExt = {
request: function(){
//adds dynamic script element to the current webpage's head tag
},
callback: function(json) {
//do something with this
}
};
myExt.request adds a dynamically added script element to a server that returns json, i want the json to be sent to myExt.callback that exists within my extension's js code.
from my extension
//from my extension, i add a script element
myExt.request();
pings the server, back into the webpage
//from server i get the following response
myExt.callback ( {"some":"json"}) ;
//but the window doesnt find a reference to myExt
how do i make a reference to myExt variable from the webpage ?
Firefox extensions run JavaScript with high privilege (chrome) and have full access to the browser. JavaScript code from a web page run unprivileged JavaScript and among other things cannot reference or interact directly with the privileged JavaScript.
In general, you have to be very careful when your extension code interacts with code coming from websites in order not to open a security hole that could allow a malicious website to execute JavaScript with chrome privileges.
You can find more information here, including code snippets if you need to exchange data between privileged and unprivileged JavaScript:
https://developer.mozilla.org/en/Security_best_practices_in_extensions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With