ruifigueira / playwright-crx

Playwright for chrome extensions
Apache License 2.0
81 stars 15 forks source link

Chromium tab crashes when calling chrome.debugger.detach after Emulation.setEmulatedMedia #2

Closed ruifigueira closed 8 months ago

ruifigueira commented 8 months ago

In recent chromium versions, when detaching playwright-crx, the corresponding tab crashes with Error code: STATUS_BREAKPOINT:

image

I was able to track down the issue to Emulation.setEmulatedMedia when setting forced-colors feature to either none or active. Even though the instruction executes successfully, it crashes the attached tab when we try to detach it using chrome.debugger.detach.

Minimal code for a chrome extension that reproduces the bug on Chromium 119.0.6045.9, Windows 11:

{
  "name": "Bug crash - forced-colors",
  "version": "0.0.1",
  "manifest_version": 3,
  "background": {
    "service_worker": "background.js",
    "type": "module"
  },
  "permissions": ["debugger", "tabs"]
}
(async () => {
  const { id: tabId } = await chrome.tabs.create({ url: 'about:blank' });
  await chrome.debugger.attach({ tabId }, '1.3');
  await chrome.debugger.sendCommand({ tabId }, 'Emulation.setEmulatedMedia', { media: "", features: [{name: "forced-colors", value: "none" }]});
  // detaching will crash the tab with 
  await chrome.debugger.detach({ tabId });
})();

In Chromium 117.0.5938.62, the issue doesn't occurr.

ruifigueira commented 8 months ago

Issue reported in chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=1499656