Change the src
attribute of the script tag to chrome://sample/content/onloadoverlay.js
Firefox extension: how to get a script to run from a load overlay
-
30-06-2023 - |
Question
I have got the extension to load and have been able to make a status appear at the bottom. I have tried to add the following code to the chrome.manifest file:
chrome.manifest:
content sample chrome/content/
overlay chrome://browser/content/browser.xul chrome://sample/content/sample.xul
Then in sample.xul, I have the following:
sample.xul:
<?xml version="1.0"?>
<overlay id="sample"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<statusbar id="status-bar" hidden="false">
<statusbarpanel id="my-panel" label="Hello, World v2" />
</statusbar>
<menubar id="main-menubar">
<menu label="Jeff" insertbefore="tools-menu">
<menupopup>
<menuitem label="About"/>
</menupopup>
</menu>
</menubar>
<script src="onloadoverlay.js"/>
</overlay>
I added the menubar and statusbar to make sure that the overlay was working which it is (so far). So in theory, the following code should be loaded from "onloadoverlay.js" when the browser starts and thus should continue to load when pages load:
onloadoverlay.js:
var myExtension = {
init: function() {
// The event can be DOMContentLoaded, pageshow, pagehide, load or unload.
if(gBrowser) gBrowser.addEventListener("DOMContentLoaded", this.onPageLoad, false);
},
onPageLoad: function(aEvent) {
var doc = aEvent.originalTarget; // doc is document that triggered the event
var win = doc.defaultView; // win is the window for the doc
// test desired conditions and do something
// if (doc.nodeName != "#document") return; // only documents
// if (win != win.top) return; //only top window.
// if (win.frameElement) return; // skip iframes/frames
alert("page is loaded \n" +doc.location.href);
}
}
window.addEventListener("load", function load(event){
window.removeEventListener("load", load, false); //remove listener, no longer needed
myExtension.init();
},false);
Please let me know if I am going about this completely wrong or if I am missing something simple. I have gotten to this point with google and several extension creation walkthrough's and other information. I would expect by the code so far that it would make a popup on page loads.
help is much appreciated,
-Jeff
Solution