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

[Feature]: Allow relative URLs in trace-viewer trace param #34493

Open
vitalets opened this issue Jan 27, 2025 · 4 comments
Open

[Feature]: Allow relative URLs in trace-viewer trace param #34493

vitalets opened this issue Jan 27, 2025 · 4 comments
Assignees
Labels

Comments

@vitalets
Copy link
Contributor

🚀 Feature Request

I propose to add support of relative URLs to the trace-viewer trace parameter.

Example

Currently, trace-viewer URLs look like this:

http://localhost:9323/trace/index.html?trace=http://localhost:9323/data/9ed7c5d3b9be501f8179e4cacebced0ccbbcac7b.zip

I'd like to request a support of relative URLs in the trace param:

http://localhost:9323/trace/index.html?trace=/data/9ed7c5d3b9be501f8179e4cacebced0ccbbcac7b.zip

If trace is relative, trace-viewer resolves it from it's hostname (localhost:9323 in the example above).
Then all other checks run as usual, e.g. checking for file:// scheme.

I've checked the trace-viewer sources, looks like it could be achieved by a tiny change next to getting trace URLs:

// resolve relative trace urls
for (let i = 0; i < newTraceURLs.length; i++) {
  const url = newTraceURLs[i];
  if (url.startsWith('/')) {
    newTraceURLs[i] = new URL(url, window.location.toString()).href;
  }
}

If approved, I'm ready to submit a PR.

Motivation

I use trace-viewer URLs in a custom HTML reporter. The report file is served via a local HTTP server, started by the user on a random port. Since the port is unknown beforehand, I cannot generate reliable trace-viewer URLs.

This small addition will simplify integration with third-party tools and help the Playwright ecosystem evolve.

@agg23
Copy link
Contributor

agg23 commented Jan 27, 2025

This sounds like a good improvement. PRs are welcome.

@agg23 agg23 self-assigned this Jan 27, 2025
@agg23 agg23 added the v1.51 label Jan 27, 2025
@vitalets
Copy link
Contributor Author

I tried implementing it and discovered that the trace-viewer accepts paths for the trace parameter. For example, a relative path:

http://localhost:9323/trace/index.html?trace=./playwright-report/data/bcfdcb3222cbd1de760f9ecd1329ad7739e6037e.zip

Or an absolute path:

http://localhost:9323/trace/index.html?trace=/Users/vitalets/projects/my-project/playwright-report/data/9ed7c5d3b9be501f8179e4cacebced0ccbbcac7b.zip

To support relative URLs in the trace parameter, we need to address the ambiguity. When I provide trace=/path/to/trace.zip, should the trace-viewer pass it through to look up on the filesystem, or should it prepend its own hostname?

I could introduce a query parameter, isUrl=true, to indicate that the provided path is expected to be a URL.
What do you think?

@agg23
Copy link
Contributor

agg23 commented Jan 29, 2025

Thinking about this further, why do you not know the current port? You know your current hostname and port; does that not match the Trace Viewer server?

@vitalets
Copy link
Contributor Author

I'm serving trace-viewer from a local static webserver, started as npx http-server. It picks free port randomly.

If I start it with the hardcoded port (e.g. npx http-server --port 1234) then I also need to configure my custom reporter to generate trace-viewer links with that port, like trace/index.html?trace=http://localhost:1234/data/.... That is less convenient and actually duplicates the config.

I think, it would be useful to make trace-viewer "servable" from a regular static server.
I assume it will also simplify a couple of places in the Playwright itself, where currently http server aliases trace/file?path=xxx to serve the xxx path statically. I found it here and here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants