/** * @license * Copyright 2016 Google LLC * SPDX-License-Identifier: Apache-2.0 */ /** * @fileoverview Audit a page to see if it's using document.write(). document.write() has terrible performance characteristics. * * *Intervention* * There is a Chrome intervention for the API: https://developers.google.com/web/updates/2016/08/removing-document-write * The intervention appears to only be enabled when the user is on a slow connnection. https://chromestatus.com/features#document.write * When it's enabled, _some_ calls to document.write() will just not do anything. They're just no-ops. * - "some" == mostly third-party situations. src: https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/script/document_write_intervention.cc?l=109&rcl=61a806621861e9abc07b3a57a6f2edae188d1742 * If this happens, there will be an error message in the console. src: https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/script/document_write_intervention.cc?l=51-61&rcl=61a806621861e9abc07b3a57a6f2edae188d1742 * - Lighthouse doesn't report here on that situation, though it'll show up in `errors-in-console` * The intervention may also not block the .write() (because the connection wasn't slow), * but it will emit a console warning. * - Lighthouse will also report that here, as the .write() call succeeded. * Demo URL: https://output.jsbin.com/qopijux/quiet * * *This Audit* * This audit reports on document.write() calls which the intervention didn't stop. * (They worked as intended). If that happens, the browser emits a verbose-level violation * console message (hidden by default) that says: * "Parser was blocked due to document.write(