From 1e0014116b7be966d513a866ff65a004feb04bdf Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 9 Dec 2015 13:29:22 -0500 Subject: [PATCH] this fixes #1004 --- platform/firefox/vapi-background.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 3c47895ed..8283747c6 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -712,8 +712,24 @@ var getTabBrowser = (function() { }; } + // https://github.com/gorhill/uBlock/issues/1004 + // Merely READING the `gBrowser` property causes the issue -- no + // need to even use its returned value... This really should be fixed + // in the browser. + // Meanwhile, the workaround is to check whether the document is + // ready. This is hacky, as the code below has to make assumption + // about the browser's inner working -- specifically that the `gBrowser` + // property should NOT be accessed before the document of the window is + // in its ready state. + return function(win) { - return win && win.gBrowser || null; + if ( win ) { + var doc = win.document; + if ( doc && doc.readyState === 'complete' ) { + return win.gBrowser || null; + } + } + return null; }; })();