1

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?

simon
  • 1,180
  • 3
  • 12
  • 33
  • where did you put this script? – Madhawa Priyashantha Apr 05 '16 at 15:04
  • I put this script in my `index.js`, this file is create automatically by `jpm init`. I followed this tutorial https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Getting_Started_%28jpm%29 @Fast Snail – simon Apr 05 '16 at 15:07
  • in this tutorial i cant see `window.addEventListener` .? i think you cant use this in `index.js` but you can use it in content script – Madhawa Priyashantha Apr 05 '16 at 15:10
  • Yes I cant see `window.addEventListener` me to, but I wonder how to do this with `jpm`, how to say is my firefox extension should start at start-up browser ? – simon Apr 05 '16 at 15:17

2 Answers2

3

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.

the8472
  • 40,999
  • 5
  • 70
  • 122
  • Yes after some research my `index.js` is load when launch firefox, so I I can do what I want in this file – simon Apr 07 '16 at 06:44
  • @simon, If this answer solved your problem, please accept it. That way the question will show up as having an accepted solution. – Makyen Aug 05 '16 at 16:10
0

@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.

schalkneethling
  • 6,327
  • 3
  • 21
  • 20