Skip to content

Migrate away from document.write? #1910

@jaidetree

Description

@jaidetree

Issue details

image

Chrome and Brave will display a warning in the console:

resize:38 [Violation] Avoid using document.write(). https://developers.google.com/web/updates/2016/08/removing-document-write

Steps to reproduce/test case

  1. Setup browser-sync to either behave as a proxy or a static server
  2. Run browser-sync
  3. Visit the browser-sync webserver
  4. Open the inspector in either Chrome or Brave

Please specify which version of Browsersync, node and npm you're running

  • Browsersync [ 2.27.5]
  • Node [16.10.0]
  • Npm [7.24.0]

It seems to me like using document.write is considered a bad-practice. Based on #1849 (comment) it was argued that it doesn't matter given its only running in development.

It's understandable that it's a non-issue given it's only used in development, but it seems to me like it would be worth fixing to avoid the warning. Subjectively, I feel it sets a better example not using APIs like document.write for devs just getting started and future web devs.

The warning does link to https://developers.google.com/web/updates/2016/08/removing-document-write but that really mostly affects production sites, which is a non-issue here.

Lastly, I would be willing to write a PR to fix it if a maintainer is onboard with changing it. My instinct would be to use document.createElement and document.body.appendChild APIs instead, open to recommendations if there's a better API. Would you be up for a PR to fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions