Repository navigation
Store page stylesheets and fonts in the trace and replay them from it - #533
Open
vishnuv688 wants to merge 2 commits into
Open
vishnuv688 wants to merge 2 commits into
vishnuv688 wants to merge 2 commits into
Conversation
The player replayed a page from its captured DOM but loaded the page's stylesheets and fonts from the live site: cross-origin fonts failed without CORS, an https player blocked http styles, a trace broke once the site changed, and opening one made requests to the tested site. In trace mode the page collector re-reads each stylesheet and font the page loaded from the browser cache and hands it over in the drain every adapter already runs. The writer stores only what each archive's documents use, each body once at resources/<sha1> with a page-resources.ndjson index, under per-resource and per-archive caps, and drops the collector's own re-reads from the network rows. The player turns stored resources into blob: URLs, resolving url() and @import against each stylesheet, and replay honours a page's own http(s) <base href>. The CSP allows blob: for styles and fonts. traceResources: 'none' | 'styles' (default 'styles', trace mode only), with trace_resources / --devtools-trace-resources / DEVTOOLS_TRACE_RESOURCES in Python. Live mode is unchanged. Closes #499 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two network rows in the backend export test lacked the required startTime and type, and the Selenium option-wiring test replaced the context's options with an object missing required fields. CI's typecheck covers test files; the build and test runs do not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Closes #499. Part of #494.
The player replayed a page from its captured DOM but loaded that page's stylesheets and fonts from the live site under test. As a result:
https, blocked anhttpsite's styles;In trace mode the zip now stores the stylesheets and fonts the page used, and the player replays them from the archive, in
show-traceand the hosted player alike. Anything not stored still loads from the site, as before. Live mode is unchanged.Type of change
Packages touched
shared(types and contracts)core(framework-agnostic capture/reporting)elements(published element/snapshot API —@wdio/elements)service(WebdriverIO adapter)nightwatch-devtools(Nightwatch adapter)selenium-devtools(Selenium adapter)selenium-devtools-py(Selenium Python adapter)backend(server)app(UI)script(page-injected runtime)trace(Trace mode)Plus
conformance(smoke fixture site and expectations, capability matrix).Capability matrix
packages/conformance/src/features.tsupdated, and tables regenerated withpnpm docs:capabilities, if this adds or changes user-facing behaviourNew feature
page-resources, backed per adapter by a test that the adapter passes the mode in its trace drain and keeps what comes back. The docs-site tables are refreshed with the docs-site PR.Notes for reviewers
Why this touches every adapter, and why the work is not there: the capture is in the page collector (
script/src/collectors/pageResources.ts), the storage and filtering intrace(shared by the JS adapters and the backend that builds Python's archives), and the replay inapp. Each adapter only passes a mode in the drain it already runs and keeps what comes back (corepage-resource-store.tsfor the JS adapters,page_resources.pyplus the backend store for Python).How it works
cache: 'force-cache', 1.8 s timeout). A same-origin stylesheet it cannot re-read falls back to itscssRules; a cross-origin one without CORS replays live. Bodies are kept only when the content type is a stylesheet or a font, skipping a small analytics host list. The drain carries the keys of what is already stored, so a new document does not re-send them.trace-network.tsdrops the matching BiDi or performance-log row only when it can place it on the browser's clock and itsSec-Fetch-Destis empty. When unsure it keeps the row, so the worst case is a leftover duplicate, never a lost page load.resources/<sha1>, indexed bypage-resources.ndjson. Each archive (per-test slices included) stores only what its own documents reference, followingurl()and@importinside stored stylesheets, capped at 1 MiB per resource and 8 MiB per archive. Old zips without the index open as before.archived-resources.tsturns stored resources intoblob:URLs, resolving each stylesheet'surl()/@importagainst the stylesheet's own URL. The rewrite runs after replay-safety filtering and writes only quotedblob:or absolute URLs. The CSP addsblob:tostyle-srcandfont-srconly, inplayer-csp.tsandvercel.json.shared/css-urls.ts) is one forward scan, no regex, tested linear on hostile input of a million characters.Behaviour change for every trace: replay now honours a page's own
<base href>(http/https only, otherwise the page URL), not only for stored resources. Before, the player always resolved against the page URL. This matches how the page itself resolved its URLs.Options:
traceResources: 'none' | 'styles', default'styles', trace mode only. Python:enable(trace_resources=...),--devtools-trace-resources, inidevtools_trace_resources, envDEVTOOLS_TRACE_RESOURCES. Images are a follow-up ('all').Not covered (README): images; cross-origin stylesheets without CORS; CSS added through the CSSOM; the page can observe the re-reads (its PerformanceObserver, RUM scripts, a service worker), and a CORS refusal logs a console error; a row without a browser-clock start time can leave a duplicate.
Review: two independent rounds. The first found one blocking issue (the end-of-test drains reset the WDIO service's "the last action navigated" flag, skipping the wait for the new page to load) and 11 more; all are fixed with tests that fail without them. The second confirmed the fixes; its four low findings are fixed too.
Testing
pnpm build,pnpm test(3731 passed, 1 skipped),pnpm test:ui(31 of 31),pnpm lint,pnpm docs:capabilities --checkare green; no workspace import leaks in any bundle.test_instrumentation.pytests fail locally with and without this PR.@font-faceand checks every adapter's zips carry both.Needs checking by hand (after
pnpm build;pnpm smoke:fixturesandexport DEVTOOLS_EXAMPLE_BASE_URL=http://127.0.0.1:4567)DEVTOOLS_MODE=tracewithpnpm demo:wdio:mocha,pnpm demo:selenium,pnpm demo:nightwatch,pnpm demo:python:pytest; then each in live mode, which should look as before with no extra stylesheet rows in Network.unzip -l <zip> | grep page-resourceslists the index;pnpm show-trace <zip>renders styled with no duplicatefixture.cssor font rows in Network.show-trace.pnpm player:hosted, open the same zips at http://localhost:4173: styled, icon rendered, no CSP errors.traceResources: 'none'(PythonDEVTOOLS_TRACE_RESOURCES=none): nopage-resources.ndjson, styles load live.Not in this PR: the images option and the docs-site mirror.
Screenshots / recordings
To be added: the-internet's login page replayed in the hosted player, before and after.
🤖 Generated with Claude Code