Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(trace viewer): support HMR #33609

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Nov 14, 2024

Adds HMR support to the trace viewer. Hopefully this is the final PR in this saga.

@Skn0tt Skn0tt self-assigned this Nov 14, 2024

This comment has been minimized.

@mxschmitt
Copy link
Member

I can confirm that this works.

@@ -48,8 +48,8 @@ const xtermDataSource: XtermDataSource = {

const searchParams = new URLSearchParams(window.location.search);
const guid = searchParams.get('ws');
const wsURL = new URL(`../${guid}`, window.location.toString());
wsURL.protocol = (window.location.protocol === 'https:' ? 'wss:' : 'ws:');
const wsURL = new URL(`/${guid}`, searchParams.get('server') ?? window.location.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

I am afraid that /guid top-level path will not work for non-top-level UI mode, for example UI mode forwarded from codespaces?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the common case, this will use the URL from ?server as the base URL. That URL doesn't have any path anyways, so ../${guid} will resolve to the same as /${guid}. As far as I know, codespaces doesn't perform any URL manipulation, but instead forwards based on ports, so this should be fine. Let me test that though.

Copy link
Member Author

Choose a reason for hiding this comment

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

ToT is broken in codespaces. If you run npx playwright test --ui --ui-host=localhost, codespaces will open up https://fantastic-space-goggles-x5p9q4v5v4g36xxx-45079.app.github.dev/trace/uiMode.html?ws=...&server=http://localhost:45079. It's the same path as outside of codespaces, but a different hostname. It loads all the static assets fine, but the server parameter continues pointing to localhost, which it cannot access.

Copy link
Member Author

Choose a reason for hiding this comment

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

this got fixed in #33664

const urlPath = `./trace/${options.webApp || 'index.html'}?${params.toString()}`;
let baseUrl = '.';
if (process.env.PW_HMR)
baseUrl = 'http://localhost:44223'; // port is hardcoded in build.js
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we need ?server parameter? Perhaps I've lost where it is added, could you please add a comment explaining?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's added in L128

@Skn0tt
Copy link
Member Author

Skn0tt commented Nov 20, 2024

I've rebased this onto the new changes in main. It should be finally ready for approval now.

This comment has been minimized.

if (traceViewerServerBaseUrl.searchParams.has('server'))
traceViewerServerBaseUrl = new URL(traceViewerServerBaseUrl.searchParams.get('server')!, traceViewerServerBaseUrl);
const clientURL = new URL(client?.url ?? self.registration.scope);
let traceViewerServerBaseUrl = new URL('../', clientURL);
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, we are trying to support relative server url here? If so, perhaps it should be relative to the clientURL instead of '../'? I find this contract to be harder to understand.

Basically:

const traceViewerServerUrl = new URL(clientURL.searchParams.get('server') ?? '../', clientURL);

Copy link
Member Author

Choose a reason for hiding this comment

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

That works, sure! We're not currently using relative server anyways, happy to change this to anything.

Copy link
Member Author

Choose a reason for hiding this comment

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

done, implemented your recommendation

@@ -48,8 +48,8 @@ const xtermDataSource: XtermDataSource = {

const searchParams = new URLSearchParams(window.location.search);
let testServerBaseUrl = new URL('../', window.location.href);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here.

This comment has been minimized.

Copy link
Contributor

Test results for "tests 1"

1 failed
❌ [playwright-test] › playwright.ct-dev-server.spec.ts:21:5 › should run dev-server and use it for tests @macos-latest-node18-1

3 flaky ⚠️ [installation tests] › playwright-cdn.spec.ts:43:7 › playwright cdn failover should work (https://playwright.azureedge.net) @package-installations-ubuntu-latest
⚠️ [chromium-library] › library/video.spec.ts:381:5 › screencast › should capture navigation @ubuntu-20.04-chromium-tip-of-tree
⚠️ [webkit-library] › library/browsercontext-clearcookies.spec.ts:92:3 › should remove cookies by domain @webkit-ubuntu-22.04-node18

37127 passed, 650 skipped
✔️✔️✔️

Merge workflow run.

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