views:

233

answers:

1

My firefox extension calls an observer function on load that intercepts http requests (http-on-modify-request) from certain domains and opens them in a new tab.

The issue I'm having is that if multiple browser windows are open (not tabs, but new browser windows), then the JS for my extension is executed multiple times, and as a result, multiple event listeners are added. All these event listeners are triggered and the intercepted http request is opened in more then one tab at once.

What's the best solution here? If there were a way to only add the event listener once, that could still be a problem, since if I were to close the browser window that added the event listener, there would then be no event listener to intercept these http requests.

A: 

You should make a variable to tell if the event is already being listened.

M28