Implement device emulation support in browser view#316749
Draft
rebornix wants to merge 1 commit into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds device emulation to the Integrated Browser editor by exposing a device picker action in the toolbar and applying corresponding CDP (and UA) overrides in the Electron main-process BrowserView, with a small UI indicator in the URL bar.
Changes:
- Introduces a new “Emulate Device…” action with a curated preset list and a URL-bar pill indicator.
- Extends browser view model/service contracts to persist and react to device emulation state.
- Applies device metrics/touch/media overrides (and clamps the WebContentsView bounds) to render pages at device dimensions.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/browserView/electron-browser/media/browser.css | Adds styling for a device emulation pill in the browser URL bar. |
| src/vs/workbench/contrib/browserView/electron-browser/features/browserEditorDeviceFeature.ts | Adds URL-bar pill + Quick Pick action to select/clear device emulation presets. |
| src/vs/workbench/contrib/browserView/electron-browser/browserView.contribution.ts | Registers the new device feature contribution. |
| src/vs/workbench/contrib/browserView/electron-browser/browserEditor.ts | Updates placeholder screenshot clipping and layout refresh when emulation toggles. |
| src/vs/workbench/contrib/browserView/common/browserView.ts | Extends the workbench model API to expose device emulation state/events and setter. |
| src/vs/platform/browserView/electron-main/browserViewMainService.ts | Exposes new dynamic event and setter on the main-process browser view service. |
| src/vs/platform/browserView/electron-main/browserViewDebugger.ts | Removes a special-case block for Emulation.setDeviceMetricsOverride. |
| src/vs/platform/browserView/electron-main/browserView.ts | Implements emulation application (CDP overrides), bounds clamping, and tracing hooks. |
| src/vs/platform/browserView/common/browserView.ts | Adds IBrowserDeviceEmulation, presets, state field, and service API surface. |
Copilot's findings
- Files reviewed: 9/9 changed files
- Comments generated: 4
Comment on lines
+613
to
+616
| // Use Electron's native API for UA. CDP's setUserAgentOverride doesn't reliably | ||
| // stick across webContents.reload() and is also scoped to the current target only. | ||
| this._view.webContents.setUserAgent(device?.userAgent ?? ''); | ||
| this.traceDeviceEmulation('setUserAgent', `"${(device?.userAgent ?? '').slice(0, 60)}…"`); |
Comment on lines
+569
to
+574
| private traceDeviceEmulation(event: string, extra?: string): void { | ||
| if (!this._deviceEmulationTraceStart) { | ||
| return; | ||
| } | ||
| const dt = Date.now() - this._deviceEmulationTraceStart; | ||
| this.logService.info(`[BrowserView][trace +${dt}ms] ${event}${extra ? ' ' + extra : ''}`); |
Comment on lines
+607
to
+611
| // Trace window: keep tracing webContents/network events for 5s after a device switch | ||
| // so we can see exactly what the page does (client-side nav, refetches, etc). | ||
| this._deviceEmulationTraceStart = Date.now(); | ||
| setTimeout(() => { this._deviceEmulationTraceStart = 0; }, 5000); | ||
| this.traceDeviceEmulation('setDeviceEmulation:start', device ? `${device.id} ${device.width}x${device.height}` : 'off'); |
Comment on lines
+363
to
+367
| // unless we initiated this navigation ourselves and already applied them. | ||
| if (this._deviceEmulation && !this._skipNextNavigateEmulationReapply) { | ||
| void this.applyDeviceEmulation(); | ||
| } | ||
| this._skipNextNavigateEmulationReapply = false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.