fix: allow null viewport to disable viewport emulation#107
fix: allow null viewport to disable viewport emulation#107Cloak-HQ merged 2 commits intoCloakHQ:mainfrom
Conversation
2af5d87 to
a9da154
Compare
|
Thanks for the clean PR, good catch on the We confirmed the bug — One thing: viewport: options.viewport ?? DEFAULT_VIEWPORT,Happy to merge this as-is and fix it ourselves, or if you'd like to add it to this PR that works too. Up to you. |
Same bug as in newContext: `??` swallows `null`, preventing users from disabling viewport emulation via `viewport: null`. Use explicit `=== undefined` check instead.
|
Thanks for pointing that out! I've applied the same fix to |
viewport=None now disables viewport emulation via Playwright's no_viewport=True, matching the JS wrapper's viewport: null behavior. Uses a sentinel to distinguish "not provided" from explicit None. Co-authored-by: kitiho <51785099+kitiho@users.noreply.github.com>
|
Thanks for the fix, @kitiho! Merged and shipped. We also applied the same fix to the Python wrapper ( Added you to the Contributors section in README as well. |
Problem
Passing
viewport: nulltolaunchPersistentContext()has no effect — the browser always launches withDEFAULT_VIEWPORT(1920×947) because the??operator treatsnullthe same asundefined.Root cause
??coalesces bothnullandundefined, so an explicitnull(which in Playwright means "disable viewport emulation and let the OS window control the size") is silently replaced byDEFAULT_VIEWPORT.Fix
Use a strict
undefinedcheck sonullis passed through to Playwright:Also update the
viewporttype inLaunchContextOptionsto acceptnull:Why it matters
Desktop apps (e.g. Electron) need the browser content to resize with the window. With
viewport: null, Playwright/Chromium uses the actual window dimensions and responds to resize events. Without this fix there is no way to opt out of the fixed 1920×947 default.