Skip to content

Add --wait-until option to control navigation completion - #199

Open
alvins82 wants to merge 1 commit into
simonw:mainfrom
alvins82:wait-until-option
Open

alvins82 wants to merge 1 commit into
simonw:mainfrom
alvins82:wait-until-option

Conversation

@alvins82

@alvins82 alvins82 commented Jul 5, 2026 •

Copy link
Copy Markdown

What

Adds a --wait-until option to every URL-loading command (shot, multi, pdf, html, javascript, accessibility, har and video). The value is passed straight through to Playwright's page.goto(..., wait_until=...) and accepts commit, domcontentloaded, load (the default) and networkidle.

Why

shot-scraper currently relies on Playwright's default wait_until="load". Some single page apps hold open long-lived connections (WebSockets, server-sent events) and never fire the load event, so navigation hangs until it hits the timeout even though the page is fully usable. There's no way to change that today short of forking or monkeypatching.

With this change:

shot-scraper 'https://my-single-page-app.example/' --wait-until domcontentloaded

takes the shot as soon as the DOM is ready.

Details

  • New shared wait_until_option decorator next to the other option helpers.
  • Threaded into each command's page.goto() call, including the full storyboard path for video (_record_storyboard → _run_storyboard_scene → _run_storyboard_action → _storyboard_goto).
  • For multi, a per-shot wait_until: key in the YAML takes precedence over the CLI default (same pattern as the other per-shot keys).
  • Backwards compatible: when the option is unset wait_until is None, which Playwright treats as its default (load), so existing behaviour is unchanged. There's a test asserting page.goto is still called with wait_until=None when the flag is omitted.
  • I left the interactive auth command out, since it's a login-session bootstrap rather than a content fetch — happy to add it if you'd prefer full consistency.

Tests & docs

  • Added tests covering: the option is offered on all eight commands, invalid choices are rejected, an end-to-end run with domcontentloaded, and that the value propagates into both the shot/take_shot dict path and the storyboard goto path (plus the None default).
  • Regenerated the --help docs with cog -r docs/*.md and added a short "Controlling when navigation is considered complete" section to screenshots.md.

All existing tests that pass on main in my environment still pass (the pre-existing har/http.server failures are unrelated environment issues and fail identically without this change).


📚 Documentation preview 📚: https://shot-scraper--199.org.readthedocs.build/en/199/

Every URL-loading command (shot, multi, pdf, html, javascript,
accessibility, har and video) now accepts --wait-until, which is passed
through to Playwright's page.goto(). It accepts commit, domcontentloaded,
load (the default) and networkidle.

This helps with single page apps that hold open long-lived connections
(WebSockets, server-sent events) and so never fire the `load` event —
today navigation to those pages hangs until it times out. Passing
--wait-until domcontentloaded lets the shot/recording proceed as soon as
the DOM is ready.

For `multi`, a per-shot `wait_until:` key in the YAML takes precedence
over the CLI default. When the option is unset wait_until is None, which
Playwright treats as its default ("load"), so behaviour is unchanged.

Docs regenerated with cog.

This branch has not been deployed

No deployments
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