playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[BUG] [Webkit] xhr recognized as navigation request with a document resource type

Open Smrtnyk opened this issue 1 year ago • 1 comments

System info

  • Playwright Version: [v1.33]
  • Operating System: [Windows 11, Ubuntu 22]
  • Browser: [WebKit]

Source code

  • [x] I provided exact source code that allows reproducing the issue locally.

Test file (self-contained)

test("doc + xhr", async ({ page }) => {
    await page.route("**/*", (route, req) => {
        if (req.isNavigationRequest() && req.resourceType() === "document") {
            return route.fulfill({
                body: `
                   <!DOCTYPE html>
                    <html>
                        <head>
                            <title>Hi</title>
                        </head>
                        <body>
                        </body>
                    </html>
                `,
                contentType: "text/html"
            });
        }
        route.fulfill();
    });

    await page.goto("http://test.local/page.html");
    expect(await page.title()).toBe("Hi");

    await page.evaluate(() => {
        const x = new XMLHttpRequest();
        x.open("GET", location.href, false);
        x.send();
    });

    await page.waitForTimeout(1000);
});

Steps

  • [Run the test] Passes on chromium and firefox
  • Fails on webkit

Expected Should also pass on webkit Actual Fails only on webkit

[Describe actual behavior] Test does the following: Loads an html page, and then dispatches an xhr to the same url as the page is on. When that xhr is intercepted, it is treated as navigation and document request, instead of an xhr. On chrome and firefox this doesn't happen.

Smrtnyk avatar May 04 '23 08:05 Smrtnyk

Debugging notes: this was already fixed upstream 12 years ago https://github.com/WebKit/WebKit/commit/aec28a5b330d5ed16e135493e712f1674161e63f but then regressed again later, most likely in this change https://github.com/WebKit/WebKit/commit/da828d1ee114047ef718d5a855e402d6c55284d8

The test covering this (added in the first mentioned change) was first obsoleted in https://github.com/WebKit/WebKit/commit/92217a88392dee42450bca2220e8c6db555f53d8 and then deleted in https://github.com/WebKit/WebKit/commit/f4220730edf707a69fad152094f049d6f3fdbd17

yury-s avatar May 20 '23 00:05 yury-s