I'm currently using this in the bootstrap.js
file. Is used to edit the client's JavaScript code in my case I'm using recentBrowserWindow.messageManager.loadFrameScript(file, true)
:
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import('resource://gre/modules/Services.jsm');
var file = 'chrome://testAddon/content/inject.js';
function startup(aData, aReason) {
var recentBrowserWindow = Services.wm.getMostRecentWindow('navigator:browser');
if(recentBrowserWindow.document.readyState == 'complete') {
recentBrowserWindow.messageManager.loadFrameScript(file, true);
}
}
inject.js:
var window = content;
var pageJS = window.wrappedJSObject;
console.log("jQuery is defined:", "jQuery" in window);
//true, jQuery is already assigned on client page.
But here the script inject.js
is running after of the client page. The question is:
How can inject
inject.js
just before the page's script execution?. What method should I use?