Skip to content

[Feature]: Allow customizing BrowserContextOptions when chromium.connectOverCDP #37627

@z0gSh1u

Description

@z0gSh1u

🚀 Feature Request

When calling chromium.connectOverCDP(endpoint) to an existing browser, Playwright enforces the colorScheme to be light regardless of the page's original. This is somehow unexpected since "connecting" to an "existing" thing should not override its "own" behavior.

In #28824 this has been discussed - forcing "light" scheme is for consistency, which is also reasonable. However I think at least there should be an escape hatch in connectOverCDP that allows to bypass this, for example, allow it to accept BrowserContextOptions and merge it with the defaults.

Currently users can only iterate through all pages and emulateMedia on each, which leads to unavoidable light-to-dark UI flickers.

Example

Open a webpage that listens the perfers-color-scheme from OS.

<!DOCTYPE html>
<html lang="en">
  <head>
    <style>
      span {
        display: none;
      }
      .light {
        display: inline;
      }
      @media (prefers-color-scheme: dark) {
        .light {
          display: none;
        }
        .dark {
          display: inline;
        }
      }
    </style>
  </head>
  <body>
    <div>
      Current prefers-color-scheme: 
      <span class="light">light</span>
      <span class="dark">dark</span>
    </div>
  </body>
</html>

Then connectOverCDP and just do nothing.

const playwright = require('playwright');

playwright.chromium.connectOverCDP('ws://127.0.0.1:9222/...').then(async (browser) => {
  await new Promise((resolve) => setTimeout(resolve, 10000));
  await browser.close();
});

Motivation

Stated in Feature Request session.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions