Skip to content

fix: verify and restore browser state after recording starts#38

Open
OfriHarlev wants to merge 1 commit intoAmElmo:mainfrom
OfriHarlev:upstream/browser-state-verification-clean
Open

fix: verify and restore browser state after recording starts#38
OfriHarlev wants to merge 1 commit intoAmElmo:mainfrom
OfriHarlev:upstream/browser-state-verification-clean

Conversation

@OfriHarlev
Copy link
Copy Markdown
Contributor

@OfriHarlev OfriHarlev commented Apr 8, 2026

Summary

  • verify the active browser URL and viewport immediately after record start
  • reapply the configured viewport after recording starts so the recording context stays aligned with the expected page state
  • parse viewport payloads robustly when agent-browser eval returns a double-encoded JSON string
  • add focused regression tests for viewport payload parsing and the post-record viewport restore flow

Problem

ProofShot can successfully open the browser and start recording, but the recording step can still leave the browser at the wrong viewport.

In local verification against patched agent-browser, a session configured for 1920x1080 with scale 1 reported:

  • without post-record viewport reapply: 1280x577
  • with post-record viewport reapply: 1920x1080

There is also a parsing edge case here: agent-browser eval can return the viewport payload as a JSON string literal containing JSON, not only as a direct JSON object. When ProofShot only parses once, it treats a valid viewport payload as unreadable and aborts startup.

Solution

This change treats browser-state verification after record start as one cohesive step:

  • reapply the configured viewport immediately after recording starts
  • verify the URL and viewport in the active browser context
  • parse viewport payloads robustly whether they arrive as direct JSON or double-encoded JSON strings

Testing

  • npm test
  • npm run build

Local verification

Using the sample app with patched agent-browser:

  • raw agent-browser recording without viewport reapply drifted to 1280x577
  • the same flow with viewport reapply stayed at 1920x1080
  • this confirms the post-record viewport restore is still necessary in ProofShot

@OfriHarlev OfriHarlev force-pushed the upstream/browser-state-verification-clean branch 2 times, most recently from 2a720f7 to 6407b27 Compare April 9, 2026 00:25
@AmElmo AmElmo self-assigned this Apr 13, 2026
@OfriHarlev OfriHarlev force-pushed the upstream/browser-state-verification-clean branch from 6407b27 to 705038e Compare April 13, 2026 15:58
@OfriHarlev
Copy link
Copy Markdown
Contributor Author

@AmElmo I rebased this PR with latest main

@OfriHarlev OfriHarlev force-pushed the upstream/browser-state-verification-clean branch from 705038e to 9f1dd86 Compare April 14, 2026 08:25
@OfriHarlev
Copy link
Copy Markdown
Contributor Author

@AmElmo any chance this can get a review?

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