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

[Bug]: Playwright routeFromHAR functionality doesn't work with gzip compressed content #34514

Open
kunal-figma opened this issue Jan 28, 2025 · 7 comments

Comments

@kunal-figma
Copy link

kunal-figma commented Jan 28, 2025

Version

1.50.0

Steps to reproduce

In this minimally reproducible example, Playwright is serving a gzip compressed javascript file to the browser using the routeFromHAR functionality. The browser, however, is unable to execute the javascript.

Steps to reproduce:

  1. Clone this repo: https://github.com/kunal-figma/playwright-bug
  2. npm i to install dependencies
  3. node index.js and notice that he browser logs an "Unexpected syntax error" vs. executing the Javscript in web.js

Expected behavior

I expect the browser to be able to execute the Javascript

Actual behavior

The browser is console logging "Unexpected syntax error" instead of executing the Javascript

Additional context

No response

Environment

System:
    OS: macOS 14.3
    CPU: (10) arm64 Apple M1 Max
    Memory: 2.80 GB / 64.00 GB
  Binaries:
    Node: 22.10.0 - /usr/local/bin/node
    npm: 10.9.0 - /usr/local/bin/npm
    pnpm: 8.15.1 - /usr/local/bin/pnpm
  IDEs:
    VSCode: 1.95.3 - /opt/homebrew/bin/code
  Languages:
    Bash: 3.2.57 - /bin/bash
  npmPackages:
    playwright: ^1.50.0 => 1.50.0
@agg23
Copy link
Contributor

agg23 commented Jan 29, 2025

Where did the HAR file come from? It doesn't appear to have come from Playwright. Due to looseness of the spec and other implementations, we can only guarantee support of HAR files generated by Playwright.

Playwright explicitly decompresses the responses it stores on disk, so they're never gziped.

@kunal-figma
Copy link
Author

@agg23 I wrote the HAR file.

I see. The HAR file I generated is pretty "standard", its just serving a file. It works in Playwright when I don't gzip compress the content, but fails when I do gzip compress it. If we want to be able to serve gzip compressed content, should we be using something like this: https://playwright.dev/docs/network#handle-requests?

@agg23
Copy link
Contributor

agg23 commented Jan 29, 2025

The HAR support works the same way as page.route(), so it will also not support a compressed body.

If we want to be able to serve gzip compressed content

Why do you want to serve gzip compressed content? It should not matter to your test or browser at all.

@kunal-figma
Copy link
Author

Why do you want to serve gzip compressed content? It should not matter to your test or browser at all.

The JS we're serving to the browser is quite large and it seems like Playwright is crashing when we serve the uncompressed JS via the HAR file. Also, when we compress the JS, the browser will cache the asset. When it's not compressed, we've noticed that the browser does not cache the asset. The caching is important to us because it means that tests will execute faster because they load the Javascript faster.

@kunal-figma
Copy link
Author

It appears this might be a limitation in CDP, does that sound right to you? https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#method-fulfillRequest The body parameter is a string

@agg23
Copy link
Contributor

agg23 commented Jan 30, 2025

It is likely a CDP limitation, yes.

Can you give us more context on your workflow and what you're trying to accomplish? We're very curious about how Playwright might better serve you. How large of files are you trying to serve? If you're serving a large scenario and would like to rely on caching, why not spin up your own simple server to serve those assets?

Playwright disables browser caching for routes so they are actually re-evaluated properly on each request. Since you cannot serve compressed files through this, you haven't seen it, but those gziped files would also not be cached. This also points towards using an external server to host the HAR data.

@kunal-figma
Copy link
Author

kunal-figma commented Jan 30, 2025

I think spinning up our own simple server will be the approach we take given the limitations. We were trying to use Playwright APIs instead since they were easily accessible. The nice thing about Playwright's network APIs is that it allows you to override server-side behavior at the same URLs that the frontend reaches out to, without having to change the URL that the frontend reaches out to. With the simple server solution, we'll have to adjust the URL that our frontend reaches out to. It's ok, just not ideal.

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

No branches or pull requests

2 participants