简体   繁体   中英

Autorun firefox extension jpm

I need help with JPM . I am trying to develop a firefox extension with JPM . I would like my extension automatically launches when opening firefox, but I can't add an event on the onLoad I know that with the overlay I can do something like :

window.addEventListener("load", function load(event){  
    console.log("hello");   
},false);

If I add this event to my JPM extension gives me an error :

JPM [error] Message: ReferenceError: window is not defined

Is it possible to do that with JPM ? Or is there another way to launch my firefox extension to the opening?

Your extension already gets loaded when you launch firefox.

How do you think the window.addEventListener gets added in the first place? It has to execute javascript code to do that.

@simon, You can also listen for load and unload events. https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload

Therefore, if you add an exports.main = function() {} in index.js, the code inside that function will be run as soon as Firefox starts up and your add-on is loaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM