XUL/Firefox: create new browser window on addon load -
i'm developing bootstrapped firefox addon. in startup
function constructing new instance of object, creates new firefox window following code:
function createwindow (cb) { const apphiddenwindow = services.appshell.applicationprovidedhiddenwindow , hidden = services.appshell.hiddendomwindow; // definition of openbrowserwindow() see // http://mxr.mozilla.org/mozilla-central/source/browser/base/content/browser.js // prior firefox 20 "private" option silently ignored let parent = apphiddenwindow ? hidden : recentwindow.getmostrecentbrowserwindow() , window = parent.openbrowserwindow({ private: true }); window.addeventlistener("load", onwindowload); return window; function onwindowload (e) { window.removeeventlistener("load", onwindowload); window.gbrowser.addeventlistener("pageshow", onpageshow); } function onpageshow (e) { dump("onpageshow\n"); try { cb(window); } catch (e) {} } }
for unknown me reasons code behaves differently in different circumstances: on firefox prior 20 if being executed on app startup, onpageshow
callback never fires. assume because gbrowser
's selectedbrowser
doesn't load homepage , stops after about:blank
has loaded. why load homepage in new window when reactivate extension manually (when firefox loaded already)?
trouble appears when yet loads homepage selectedbrowser
(in newer fx versions): in case doesn't start loading url, specified me , instead continues load homepage.
so how can determine if gbrowser
gonna load homepage or not? , why behave differently on app startup , on addon reactivation?
ps: above code work 1 must these import
s , use following fallback:
cu.import("resource://gre/modules/services.jsm"); try { cu.import("resource:///modules/recentwindow.jsm"); } catch (e) { // firefox prior v20 var recentwindow = { getmostrecentbrowserwindow: function () services.wm.getmostrecentwindow("navigator:browser") }; }
it seems wrong in of assumptions. don't have wait until pageshow
event. after long research found bug. according there observer notification browser-delayed-startup-finished
enough start doing things had window
.
Comments
Post a Comment