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 lo开发者_开发百科oks 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?
You can use a JavaScript code module to make sure your code is only executed once.
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
精彩评论