playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Bug]: page.WaitForResponse() triggers on OPTIONS in Firefox

Open mkrakker opened this issue 7 months ago • 0 comments

Version

1.52.0

Steps to reproduce

Trigger a request subjected to CORS; wait for the response with page.waitForResponse() using a regexp.

Minimal reproduction:

  1. Clone the repo at https://github.com/mkrakker/playwright-ff-waitforresponse
  2. npm i
  3. npm playwright test - the test will fail of Firefox only
  4. Change the Playwright version to something prior to 1.52.0 eg. 1.51.1
  5. Run steps 2 and 3 above again - the test will pass on all browsers

Expected behavior

When running the test in Firefox, page.waitForResponse() should consistently resolve with the response corresponding to the final POST request, not the preflight OPTIONS request. The test should pass, which is the current behavior observed in Chromium and WebKit, and was the behavior in Firefox prior to version 1.52.0.

Actual behavior

Starting with Playwright v1.52.0, when the test is run against Firefox, page.waitForResponse() resolves with the response to the initial preflight OPTIONS request. (the other browsers are not affected)

Additional context

My primary concern is the inconsistency in behavior between Firefox and other browsers (Chromium, WebKit) that was introduced, as demonstrated by the reproduction example. Previously, all browsers handled this scenario uniformly.

While one could argue that matching the OPTIONS request is technically valid since it's the first response that matches the URL predicate, the introduced change breaks cross-browser compatibility for existing tests.

A possible workaround is to make the predicate for more specific to include the HTTP method: waitForResponse:

const postResponsePromise = page.waitForResponse(
    (response) =>
        response.request().method() === 'POST' &&
        /myServer\/api/.test(response.url())
);

(which, to be honest, should be best practice...)

The issue is valid for v1.53 as well.

Environment

System:
    OS: Windows 11 10.0.26100
    CPU: (16) x64 Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz
    Memory: 46.10 GB / 63.76 GB
  Binaries:
    Node: 24.0.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD
    npm: 11.3.0 - C:\Program Files\nodejs\npm.CMD
  IDEs:
    VSCode: 1.98.2 - C:\Program Files\Microsoft VS Code\bin\code.CMD
  Languages:
    Bash: 5.1.16 - C:\WINDOWS\system32\bash.EXE
  npmPackages:
    @playwright/test: 1.52.0 => 1.52.0

mkrakker avatar Jun 14 '25 11:06 mkrakker