Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only have Firefox extension code run once per session

I am creating a Firefox extension that requires the user to login. Each time a new window, but not new tab is opened, the 'code' for the extension is run. I would prefer that the code is only run one time per session.

The setup of the extension looks like this. (let me know if I am missing anything):

in chrome manifest: overlay chrome://browser/content/browser.xul chrome://my/overlay.xul

in overlay.xul:
<overlay id="socialSidebarOverlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://my/code.js" />
</overlay>

in code.js:
alert('being called')

The problem is that "being called" should only be displayed when Firefox starts up, not when new tabs or windows are opened. What would be a way to accomplish this?

like image 277
Alexis Avatar asked Oct 14 '22 20:10

Alexis


2 Answers

You can use a JavaScript code module to make sure your code is only executed once.

like image 74
sdwilsh Avatar answered Oct 18 '22 03:10

sdwilsh


You might want to observe (and act on) one of the possible Mozilla Observer Notifications

Either actually act on something when starting up, or in you extension check for a particular value that is reset when the browser closes [this can be tricky, as abnormal shutdowns may not reset].

See Also: Receiving Startup Notifications

like image 28
Michael Paulukonis Avatar answered Oct 18 '22 03:10

Michael Paulukonis