Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: include.preload.js

Issue 29436567: Issue 3200 - Delay initialization for prerendered documents (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Move common logic into separate function Created Aug. 24, 2017, 2:06 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « composer.postload.js ('k') | safari/ext/background.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.preload.js
===================================================================
--- a/include.preload.js
+++ b/include.preload.js
@@ -574,23 +574,46 @@
this.propertyFilters.load(function()
{
propertyFiltersLoaded = true;
checkLoaded();
});
}
};
+function whenDocumentVisible(callback)
+{
+ if (document.visibilityState == "prerender")
+ {
+ // For prerendered documents, wait until the document is made visible. We
+ // do not have access to the page property of the SafariBrowserTab object
+ // associated with this document until it is visible. Without the page
+ // property, we cannot get a response from the background page.
+ let onVisibilitychange = function()
+ {
+ document.removeEventListener("visibilitychange", onVisibilitychange);
+ callback();
+ };
+
+ document.addEventListener("visibilitychange", onVisibilitychange);
+ }
+ else
+ {
+ callback();
+ }
+}
+
if (document instanceof HTMLDocument)
{
checkSitekey();
wrapWebSocket();
var elemhide = new ElemHide();
- elemhide.apply();
+
+ whenDocumentVisible(elemhide.apply.bind(elemhide));
document.addEventListener("error", function(event)
{
checkCollapse(event.target);
}, true);
document.addEventListener("load", function(event)
{
« no previous file with comments | « composer.postload.js ('k') | safari/ext/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld