Title: [246764] trunk/Source
Revision
246764
Author
[email protected]
Date
2019-06-24 15:22:42 -0700 (Mon, 24 Jun 2019)

Log Message

Pages using Google's anti-flicker optimization may take ~5 seconds to do initial paint
https://bugs.webkit.org/show_bug.cgi?id=199173
<rdar://problem/45968770>

Reviewed by Geoffrey Garen.

Source/WebCore:

Pages using Google's anti-flicker optimization [1] take ~5 seconds to do initial paint when
analytics.js load is blocked by a content blocker.

To address the issue, this patch introduces a quirk behind an experimental feature flag that
calls window.dataLayer.hide.end() on the page when the load of https://www.google-analytics.com/analytics.js
is blocked by a content blocker. Note that this is more robust than dropping the 'async-hide'
class from document.documentElement since the class name is customizable by the caller.
A message is logged in the console when the quirk causes window.dataLayer.hide.end() to get called
early.

[1] https://developers.google.com/optimize/

* contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
* page/Settings.yaml:

Source/WebKit:

Add experimental feature for the quirk.

* Shared/WebPreferences.yaml:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (246763 => 246764)


--- trunk/Source/WebCore/ChangeLog	2019-06-24 21:37:26 UTC (rev 246763)
+++ trunk/Source/WebCore/ChangeLog	2019-06-24 22:22:42 UTC (rev 246764)
@@ -1,3 +1,27 @@
+2019-06-24  Chris Dumez  <[email protected]>
+
+        Pages using Google's anti-flicker optimization may take ~5 seconds to do initial paint
+        https://bugs.webkit.org/show_bug.cgi?id=199173
+        <rdar://problem/45968770>
+
+        Reviewed by Geoffrey Garen.
+
+        Pages using Google's anti-flicker optimization [1] take ~5 seconds to do initial paint when
+        analytics.js load is blocked by a content blocker.
+
+        To address the issue, this patch introduces a quirk behind an experimental feature flag that
+        calls window.dataLayer.hide.end() on the page when the load of https://www.google-analytics.com/analytics.js
+        is blocked by a content blocker. Note that this is more robust than dropping the 'async-hide'
+        class from document.documentElement since the class name is customizable by the caller.
+        A message is logged in the console when the quirk causes window.dataLayer.hide.end() to get called
+        early.
+
+        [1] https://developers.google.com/optimize/
+
+        * contentextensions/ContentExtensionsBackend.cpp:
+        (WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
+        * page/Settings.yaml:
+
 2019-06-24  John Wilander  <[email protected]>
 
         Remove IsITPFirstPartyWebsiteDataRemovalEnabled as runtime check

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp (246763 => 246764)


--- trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp	2019-06-24 21:37:26 UTC (rev 246763)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp	2019-06-24 22:22:42 UTC (rev 246764)
@@ -43,6 +43,9 @@
 #include "FrameLoaderClient.h"
 #include "Page.h"
 #include "ResourceLoadInfo.h"
+#include "ScriptController.h"
+#include "ScriptSourceCode.h"
+#include "Settings.h"
 #include <wtf/URL.h>
 #include "UserContentController.h"
 #include <wtf/NeverDestroyed.h>
@@ -231,6 +234,13 @@
         }
         if (results.summary.blockedLoad)
             currentDocument->addConsoleMessage(MessageSource::ContentBlocker, MessageLevel::Info, makeString("Content blocker prevented frame displaying ", mainDocumentURL.string(), " from loading a resource from ", url.string()));
+        
+            // Quirk for content-blocker interference with Google's anti-flicker optimization (rdar://problem/45968770).
+            // https://developers.google.com/optimize/
+            if (currentDocument->settings().googleAntiFlickerOptimizationQuirkEnabled() && url == "https://www.google-analytics.com/analytics.js"_str) {
+                if (auto* frame = currentDocument->frame())
+                    frame->script().evaluate(ScriptSourceCode { "try { window.dataLayer.hide.end(); console.log('Called window.dataLayer.hide.end() in frame ' + document.URL + ' because the content blocker blocked the load of the https://www.google-analytics.com/analytics.js script'); } catch (e) { }"_s });
+            }
     }
 
     return results;

Modified: trunk/Source/WebCore/page/Settings.yaml (246763 => 246764)


--- trunk/Source/WebCore/page/Settings.yaml	2019-06-24 21:37:26 UTC (rev 246763)
+++ trunk/Source/WebCore/page/Settings.yaml	2019-06-24 22:22:42 UTC (rev 246764)
@@ -153,6 +153,9 @@
 disableScreenSizeOverride:
   initial: false
 
+googleAntiFlickerOptimizationQuirkEnabled:
+  initial: true
+
 # This is a quirk we are pro-actively applying to old applications. It changes keyboard event dispatching,
 # making keyIdentifier available on keypress events, making charCode available on keydown/keyup events,
 # and getting keypress dispatched in more cases.

Modified: trunk/Source/WebKit/ChangeLog (246763 => 246764)


--- trunk/Source/WebKit/ChangeLog	2019-06-24 21:37:26 UTC (rev 246763)
+++ trunk/Source/WebKit/ChangeLog	2019-06-24 22:22:42 UTC (rev 246764)
@@ -1,3 +1,15 @@
+2019-06-24  Chris Dumez  <[email protected]>
+
+        Pages using Google's anti-flicker optimization may take ~5 seconds to do initial paint
+        https://bugs.webkit.org/show_bug.cgi?id=199173
+        <rdar://problem/45968770>
+
+        Reviewed by Geoffrey Garen.
+
+        Add experimental feature for the quirk.
+
+        * Shared/WebPreferences.yaml:
+
 2019-06-24  John Wilander  <[email protected]>
 
         Remove IsITPFirstPartyWebsiteDataRemovalEnabled as runtime check

Modified: trunk/Source/WebKit/Shared/WebPreferences.yaml (246763 => 246764)


--- trunk/Source/WebKit/Shared/WebPreferences.yaml	2019-06-24 21:37:26 UTC (rev 246763)
+++ trunk/Source/WebKit/Shared/WebPreferences.yaml	2019-06-24 22:22:42 UTC (rev 246764)
@@ -55,6 +55,13 @@
    humanReadableDescription: "Block top-level redirects by third-party iframes"
    category: experimental
 
+GoogleAntiFlickerOptimizationQuirkEnabled:
+   type: bool
+   defaultValue: true
+   humanReadableName: "Quirk to prevent delayed initial painting on sites using Google's Anti-Flicker optimization"
+   humanReadableDescription: "Quirk to prevent delayed initial painting on sites using Google's Anti-Flicker optimization"
+   category: experimental
+
 JavaEnabled:
   type: bool
   defaultValue: false
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to