Skip to content

Implement device emulation support in browser view#316749

Draft
rebornix wants to merge 1 commit into
mainfrom
rebornix/tense-catshark
Draft

Implement device emulation support in browser view#316749
rebornix wants to merge 1 commit into
mainfrom
rebornix/tense-catshark

Conversation

@rebornix
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings May 16, 2026 05:12
@rebornix rebornix self-assigned this May 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants