0

I am working on Firefox extension that overwrite new tab page and I need to hide my page URL from address bar. I use this code:

if (gInitialPages.indexOf(NEW_TAB_URL)===-1)  gInitialPages.push(NEW_TAB_URL);

It works correctly in XUL Overlay code, but I'm getting an error when I try to make my application restartless and move this code to bootstrap.js:

gInitialPages is not defined

So, how can I use gInitialPages (or anything similar) in bootstrapped extensions?

nmaier
  • 32,336
  • 5
  • 63
  • 78
And390
  • 1,550
  • 2
  • 16
  • 22
  • Along with nmaiers solution below here's another boiler plate you can use: https://gist.github.com/Noitidart/1c7ab2c49c7640ff84db just edit in the loadIntoWindow and unloadFromWindow. – Noitidart Feb 22 '15 at 21:44
  • It seems your current code version throws ReferenceError: Services is not defined (missing import?) – And390 Feb 23 '15 at 19:15
  • Import services with Cu.import('resources://gre/modules/Services.jsm') – Noitidart Feb 23 '15 at 23:45

1 Answers1

1

Bootstrapped/restartless extensions do NOT automagically run in the context of (a) window(s). bootstrap.js runs in an own context, only once per application instance, not in the browser window.

You'll need to:

  • Manually enumerate all existing browser windows.
  • Listen for new browser windows as they are opened.

And then manipulate the variable in those windows.

See Mardak's example on how you could do that, in particular watchWindows and unload.

nmaier
  • 32,336
  • 5
  • 63
  • 78
  • Thanks for code example, it's work (with window.gInitialPages). Merely, I thought that gInitialPages must be somewhere in "global" context. – And390 Feb 23 '15 at 19:04