Skip to content

fix(browse): add viewport auto to unpin a fixed viewport without restart#1881

Open
jbetala7 wants to merge 3 commits into
garrytan:mainfrom
jbetala7:oss/fix-1059-viewport-auto
Open

fix(browse): add viewport auto to unpin a fixed viewport without restart#1881
jbetala7 wants to merge 3 commits into
garrytan:mainfrom
jbetala7:oss/fix-1059-viewport-auto

Conversation

@jbetala7

@jbetala7 jbetala7 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #1059

Problem

browse viewport WxH pins the viewport with Playwright's setViewportSize, overriding the launch-time viewport: null that lets the viewport follow the real Chrome window. Once pinned there was no way back to window-following short of browse restart, which kills the Chrome session (and drops a /connect-chrome headed attachment back to launched). Skills that set a breakpoint as a side-effect (responsive testing, benchmarks) leave the browser stuck at that size, so the visible Chrome window ends up larger than the viewport Claude renders into.

Repro (before)

$B viewport 1280x520
$B js "window.innerWidth + 'x' + window.innerHeight"   # 1280x520
# resize Chrome window manually -> viewport stays 1280x520, no way back without restart

Fix

Add browse viewport auto (aliases reset / unpin): it clears the pin and restores window-following without tearing down the session.

  • Rebuilds the context with viewport: null through the same recreateContext() path that viewport --scale already uses, so cookies, storage, and open tab URLs are preserved.
  • Resets deviceScaleFactor to 1, since Playwright forbids a custom scale alongside a null viewport.
  • Refused in headed mode (/connect-chrome), where the viewport already tracks the real browser window — consistent with how viewport --scale refuses headed mode.
  • viewport auto --scale <n> is rejected as contradictory.

A new private viewportContextOptions() helper is the single source of the viewport/scale slice of the context options, used by both the initial launch and both recreateContext paths, so the three sites can't drift.

Testing

bun test browse/test/commands.test.ts (227 pass) and browse/test/handoff.test.ts (15 pass) — both exercise recreateContext. Four new tests in the viewport auto (unpin) block assert:

  • viewport auto clears a pinned size (page.viewportSize() -> null)
  • reset / unpin are accepted aliases
  • viewport auto resets deviceScaleFactor to 1
  • viewport auto --scale is rejected

All four fail on main, where viewport auto is parsed as a malformed size and throws the usage error — confirming the capability was genuinely absent.

bun run gen:skill-docs regenerated the command-reference tables and llms.txt; skill-validation + gen-skill-docs quality suites pass (719 tests).

Notes / risk

  • No behavior change at launch or for existing viewport WxH / viewport --scale calls (the launch path resolves to the same pinned options when viewportAuto is false).
  • The eval / report CI jobs may fail on external-fork auth (empty-env), which is the known non-actionable fork-secrets limitation; code, static, and Windows checks should pass.

🤖 Generated with Claude Code

jbetala7 and others added 3 commits June 5, 2026 16:22
…start

`browse viewport WxH` pins the viewport via setViewportSize, overriding the
launch-time `viewport: null` that lets the viewport follow the real window.
Once pinned there was no way back to window-following short of `browse restart`,
which kills the Chrome session. Skills that set a breakpoint as a side-effect
(responsive testing, benchmarks) left the browser stuck at that size.

Add `viewport auto` (aliases `reset`/`unpin`): it rebuilds the context with
`viewport: null` the same way `viewport --scale` rebuilds it, preserving
cookies, storage, and tab URLs, and resets deviceScaleFactor to 1 (Playwright
forbids a custom scale with a null viewport). Refused in headed mode, where the
viewport already tracks the real browser window. `viewport auto --scale` is
rejected as contradictory.

Closes garrytan#1059

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Asserts viewport auto clears a pinned size (page.viewportSize() -> null),
that reset/unpin are accepted aliases, that auto resets deviceScaleFactor to 1,
and that `viewport auto --scale` is rejected. All four fail on main, where
`viewport auto` is parsed as a malformed size.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds a `viewport auto` example to the responsive-testing recipe and regenerates
the command reference tables from commands.ts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Jun 5, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

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.

browse: add viewport auto / viewport reset to unpin fixed viewport

1 participant