Repository navigation
fix: clear device metrics overrides when a DevTools client disconnects - #52254
Conversation
|
Heads up: Windows CI builds moved to new runners on Monday and the old ones have now been removed. This branch predates that, so its Windows build jobs still point at the old runners and will sit queued forever if CI runs again. Rebasing on |
When a debugger client set Emulation.setDeviceMetricsOverride and then went away without sending Emulation.clearDeviceMetricsOverride (killed process, dropped websocket, or plain Target.detachFromTarget), the emulated view size leaked: the page kept laying out at the override size instead of the window size, WebContentsImpl::GetSizeForMainFrame() re-applied the stale size to every new main frame on navigation, and no later session could clear it because a fresh session's EmulationHandler early-returns from clearDeviceMetricsOverride when its own device_emulation_enabled_ is false. Only relaunching the app recovered. The root cause is upstream: EmulationHandler::Disable(), which runs on session teardown, disables the renderer-side device emulation but never calls WebContentsImpl::ClearDeviceEmulationSize(), unlike the explicit clearDeviceMetricsOverride path. Renderer-side emulation is correctly torn down, so everything that leaks is browser-side and reachable from the embedder. Fix it without a chromium patch: track in the DevToolsManagerDelegate which client channels have set device metrics overrides (HandleCommand sees every command), and when such a channel detaches without having cleared them, restore the WebContents device emulation size. Channels that never set overrides are untouched, so an unrelated client detaching - a webContents.debugger detach, an auto-attached OOPIF session going away - does not disturb another session's active emulation. Adds a regression spec that sets an override over a raw CDP websocket, destroys the TCP connection without a close frame, and asserts the page returns to the window size; it fails on unpatched builds.
Also cover the webContents.debugger detach path in the debugger spec.
4119608 to
35f1e06
Compare
|
Release Notes Persisted
|
|
I was unable to backport this PR to "43-x-y" cleanly; |
|
I was unable to backport this PR to "44-x-y" cleanly; |
|
@VerteDinde has manually backported this PR to "44-x-y", please check out #52930 |
#52930) fix: clear device metrics overrides when a DevTools client disconnects (#52254) (cherry picked from commit 084e02b) Co-authored-by: Shelley Vohr <[email protected]>
|
@VerteDinde has manually backported this PR to "43-x-y", please check out #52946 |
|
@codebytere has manually backported this PR to "42-x-y", please check out #53133 |
#52946) * fix: clear device metrics overrides when a DevTools client disconnects (#52254) (cherry picked from commit 084e02b) * test: use the ws v7 client API on this branch * test: use a default import for the ws client constructor The namespace import is not constructable under tsconfig.spec.json (nodenext implies esModuleInterop), and new-cap rejects `new ws()`. --------- Co-authored-by: Shelley Vohr <[email protected]>
Description of Change
When a CDP client sets
Emulation.setDeviceMetricsOverrideand disconnects without clearing it (killed process, dropped websocket), the page stays pinned at the override size: the view keeps its emulated size, andWebContentsImpl::GetSizeForMainFrame()re-applies it on every navigation. Only relaunching the app recovers. Root cause is upstream — session teardown (EmulationHandler::Disable()) skips theClearDeviceEmulationSize()cleanup that an explicit Emulation.clearDeviceMetricsOverride performs.This fixes it in Electron's
DevToolsManagerDelegate, which content notifies for every DevTools client regardless of transport — remote-debugging websocket clients,webContents.debugger, the bundled DevTools frontend and extensions all attach, dispatch and detach through the sameDevToolsSessionpath, and all of them hit the same missing cleanup inEmulationHandler::Disable().HandleCommand()records which client channels hold an unclearedEmulation.setDeviceMetricsOverride, andClientDetached()restores the WebContents' device emulation size when such a channel goes away. The bookkeeping is per channel, so a detach only undoes that channel's own override: if another still-attached client holds an override on the same WebContents, the size is left alone until that client clears it or detaches.Verified affected: 42.5.1, 43.0.0, main, and stock Chromium — an upstream fix in EmulationHandler::Disable() is the long-term home for this. Includes regression specs for both entry points: one sets an override over a raw remote-debugging websocket, severs the connection, and asserts the page returns to the window size; the other does the same through
webContents.debugger.detach().Checklist
npm testpassesRelease Notes
Notes: Fixed DevTools device metrics overrides persisting indefinitely when a remote debugging client disconnected without clearing them.