Skip to content

fix(trace): replay sub-resources from archive in trace snapshot CLI#40632

Merged
Skn0tt merged 2 commits into
microsoft:mainfrom
Skn0tt:fix-trace-snapshot-subresources
May 7, 2026
Merged

fix(trace): replay sub-resources from archive in trace snapshot CLI#40632
Skn0tt merged 2 commits into
microsoft:mainfrom
Skn0tt:fix-trace-snapshot-subresources

Conversation

@Skn0tt

@Skn0tt Skn0tt commented May 5, 2026

Copy link
Copy Markdown
Member

Summary

  • The trace snapshot CLI (and trace serve) only replayed the recorded HTML; sub-resources fetched live from the original origin, so snapshots rendered unstyled whenever that origin was unreachable.
  • Serve sub-resources from the trace archive via a small inline service worker on a bootstrap page. Cross-origin fetches forward to a /__pwsnapshot/resource endpoint that delegates to SnapshotServer.serveResource. Same path works for both trace snapshot and trace serve.

The trace snapshot CLI (and `trace serve`) only served the recorded
HTML; sub-resources like stylesheets, images, and fonts were fetched
live from the original origin, which meant snapshots would render
without styles whenever the origin was unreachable.

Serve sub-resources from the trace archive via a small service
worker registered on a bootstrap page. The service worker forwards
cross-origin requests to a `/__pwsnapshot/resource` endpoint on the
CLI HTTP server, which delegates to `SnapshotServer.serveResource`.
Same code path works for both `trace snapshot` and `trace serve`.
@Skn0tt Skn0tt force-pushed the fix-trace-snapshot-subresources branch from 92381c0 to dd738c6 Compare May 5, 2026 11:26
@Skn0tt Skn0tt requested a review from dgozman May 5, 2026 11:43
response.statusCode = 200;
response.setHeader('Content-Type', 'application/javascript');
response.setHeader('Service-Worker-Allowed', '/');
response.end(`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract this from a string literal? I find things like this hard to maintain.

@github-actions

This comment has been minimized.

@Skn0tt Skn0tt requested a review from dgozman May 5, 2026 12:18
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Test results for "MCP"

1 failed
❌ [webkit] › mcp/dashboard.spec.ts:207 › should enter annotate mode on fresh dashboard.tsx mount with -s --annotate @mcp-windows-latest-webkit

6906 passed, 1062 skipped


Merge workflow run.

@pavelfeldman pavelfeldman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I like the code fork, why doesn't it work out of the box?

@Skn0tt

Skn0tt commented May 5, 2026

Copy link
Copy Markdown
Member Author

Subresource URLs are not rewritten, so they to whatever was the original host. In trace viewer, we also use a service worker to catch them.

@Skn0tt

Skn0tt commented May 7, 2026

Copy link
Copy Markdown
Member Author

mirroring offline discussion: putting a SW on localhost:<port> potentially poisons future sites on that hostname with the service worker.

@Skn0tt Skn0tt merged commit cb03945 into microsoft:main May 7, 2026
16 of 17 checks passed
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.

3 participants