Changeset 246764 in webkit


Ignore:
Timestamp:
Jun 24, 2019 3:22:42 PM (5 years ago)
Author:
Chris Dumez
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:
Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r246763 r246764  
     12019-06-24  Chris Dumez  <cdumez@apple.com>
     2
     3        Pages using Google's anti-flicker optimization may take ~5 seconds to do initial paint
     4        https://bugs.webkit.org/show_bug.cgi?id=199173
     5        <rdar://problem/45968770>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Pages using Google's anti-flicker optimization [1] take ~5 seconds to do initial paint when
     10        analytics.js load is blocked by a content blocker.
     11
     12        To address the issue, this patch introduces a quirk behind an experimental feature flag that
     13        calls window.dataLayer.hide.end() on the page when the load of https://www.google-analytics.com/analytics.js
     14        is blocked by a content blocker. Note that this is more robust than dropping the 'async-hide'
     15        class from document.documentElement since the class name is customizable by the caller.
     16        A message is logged in the console when the quirk causes window.dataLayer.hide.end() to get called
     17        early.
     18
     19        [1] https://developers.google.com/optimize/
     20
     21        * contentextensions/ContentExtensionsBackend.cpp:
     22        (WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
     23        * page/Settings.yaml:
     24
    1252019-06-24  John Wilander  <wilander@apple.com>
    226
  • trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp

    r245508 r246764  
    4444#include "Page.h"
    4545#include "ResourceLoadInfo.h"
     46#include "ScriptController.h"
     47#include "ScriptSourceCode.h"
     48#include "Settings.h"
    4649#include <wtf/URL.h>
    4750#include "UserContentController.h"
     
    232235        if (results.summary.blockedLoad)
    233236            currentDocument->addConsoleMessage(MessageSource::ContentBlocker, MessageLevel::Info, makeString("Content blocker prevented frame displaying ", mainDocumentURL.string(), " from loading a resource from ", url.string()));
     237       
     238            // Quirk for content-blocker interference with Google's anti-flicker optimization (rdar://problem/45968770).
     239            // https://developers.google.com/optimize/
     240            if (currentDocument->settings().googleAntiFlickerOptimizationQuirkEnabled() && url == "https://www.google-analytics.com/analytics.js"_str) {
     241                if (auto* frame = currentDocument->frame())
     242                    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 });
     243            }
    234244    }
    235245
  • trunk/Source/WebCore/page/Settings.yaml

    r246444 r246764  
    154154  initial: false
    155155
     156googleAntiFlickerOptimizationQuirkEnabled:
     157  initial: true
     158
    156159# This is a quirk we are pro-actively applying to old applications. It changes keyboard event dispatching,
    157160# making keyIdentifier available on keypress events, making charCode available on keydown/keyup events,
  • trunk/Source/WebKit/ChangeLog

    r246763 r246764  
     12019-06-24  Chris Dumez  <cdumez@apple.com>
     2
     3        Pages using Google's anti-flicker optimization may take ~5 seconds to do initial paint
     4        https://bugs.webkit.org/show_bug.cgi?id=199173
     5        <rdar://problem/45968770>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Add experimental feature for the quirk.
     10
     11        * Shared/WebPreferences.yaml:
     12
    1132019-06-24  John Wilander  <wilander@apple.com>
    214
  • trunk/Source/WebKit/Shared/WebPreferences.yaml

    r246763 r246764  
    5454   humanReadableName: "Block top-level redirects by third-party iframes"
    5555   humanReadableDescription: "Block top-level redirects by third-party iframes"
     56   category: experimental
     57
     58GoogleAntiFlickerOptimizationQuirkEnabled:
     59   type: bool
     60   defaultValue: true
     61   humanReadableName: "Quirk to prevent delayed initial painting on sites using Google's Anti-Flicker optimization"
     62   humanReadableDescription: "Quirk to prevent delayed initial painting on sites using Google's Anti-Flicker optimization"
    5663   category: experimental
    5764
Note: See TracChangeset for help on using the changeset viewer.