playwright: [BUG] [Chromium/WebKit] Request object does not contain postData for file/blob

Context:

System:

  • OS: Windows 10 10.0.19043

Binaries:

  • Node: 12.13.1 - C:\Program Files\nodejs\node.EXE
  • Yarn: 1.19.1 - ~\AppData\Roaming\npm\yarn.CMD
  • npm: 6.14.2 - C:\Program Files\nodejs\npm.CMD

Languages:

  • Bash: 4.4.20 - C:\WINDOWS\system32\bash.EXE

npmPackages:

  • playwright: ^1.10.0 => 1.10.0 / tip-of-tree

Code Snippet

Help us help you! Put down a short code snippet that illustrates your bug and that we can run and debug locally. For example:

const playwright = require('.');

(async () => {
  const browser = await playwright.webkit.launch();
  const page = await browser.newPage();

  await page.goto('http://example.com');

  const requestPromise = page.waitForRequest(() => true);
  const [request] = await Promise.all([
    page.waitForRequest("**/*"),
    page.evaluate(() => {
      var file = new File(['file-contents'], 'filename.txt');

      fetch('/data', {
        method: 'POST',
        headers: {
          'content-type': 'application/octet-stream'
        },
        body: file
      });
    })
  ])
  console.info('request.method()', request.method());
  console.info('request.url()', request.url());
  console.info('request.headers()', request.headers());
  console.info('request.postData()', request.postData());
})();

Describe the bug

the request.postData() contains null in Chromium and WebKit. In Firefox it’s filled.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 28
  • Comments: 27 (7 by maintainers)

Commits related to this issue

Most upvoted comments

chromium bug is closed as Wontfix, https://bugs.chromium.org/p/chromium/issues/detail?id=1058404. Is there any way to route multipart/form-data requests and get not null postData? (using chrome/chromium)

I’m facing this issue, but not on all my playwright project.

I’ve 2 projects with e2e, both use chromium, and i mock request to get postDataJson() On the first project is working fine, i get the value that i need. On the second project i get undifined, like the bug you describe here.

My workaround for the second project is to use firefox and it’s working fine.

But i don’t understand why is working on the first and not on the second project… The depenedencies are the same, the mock request to get postDataJson is the same.

I’m surprise this issue have 2 years old !

The link above seems to indicate this is a problem in Chromium, not Playwright. However, if you follow the discussion details it does not seem like the Chromium folks “are on it”.

Same for the JS version with Chromium and contentType application/json on PUT and POST. Works with Firefox for the same requests.

A bit of a hack for ky users, you can use a hook to prevent ky from cloning responses :

    hooks : {
      beforeRequest: [
        (request: Request) => {
          request.clone = () => request
          return request
        }
      ],
    },

There must be some difference between your projects. From what I understood, problem is when you or libraries are using request.clone(). In that case, postData is empty and it’s a Chromium bug, not playwright. But Chromium has that bug since 2020, and who knows if they’ll ever fix it, so maybe PlayWright could introduce some workaround.

Facing the same issue. The postData is always null but in network tab its clear that the data exists. In my case it is normal json payload post request. I am using the java binding at the moment.

Thanks for filing! Short of using a proxy, I don’t think there are any good workarounds at this time. These look like bugs in chromium and our webkit. It might take some time to fix, but I’m on the case!