diff --git a/tests/assets/preload.html b/tests/assets/preload.html
new file mode 100644
index 0000000000..dc10ff6d69
--- /dev/null
+++ b/tests/assets/preload.html
@@ -0,0 +1,5 @@
+
+
+
hello, world!
diff --git a/tests/page/page-request-continue.spec.ts b/tests/page/page-request-continue.spec.ts
index 3373ea2551..6befd3986c 100644
--- a/tests/page/page-request-continue.spec.ts
+++ b/tests/page/page-request-continue.spec.ts
@@ -349,3 +349,27 @@ it('should delete the origin header', async ({ page, server, isAndroid, browserN
expect(interceptedRequest.headers()['origin']).toEqual(undefined);
expect(serverRequest.headers.origin).toBeFalsy();
});
+
+it('should continue preload link requests', async ({ page, server, browserName }) => {
+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/16745' });
+ it.fixme(browserName === 'webkit', 'Preload requests are aborted in WebKit when interception is enabled');
+ let intercepted = false;
+ await page.route('**/one-style.css', route => {
+ intercepted = true;
+ route.continue({
+ headers: {
+ ...route.request().headers(),
+ 'custom': 'value'
+ }
+ });
+ });
+ const [serverRequest] = await Promise.all([
+ server.waitForRequest('/one-style.css'),
+ page.goto(server.PREFIX + '/preload.html')
+ ]);
+ expect(serverRequest.headers['custom']).toBe('value');
+ await page.waitForFunction(() => (window as any).preloadedStyles);
+ expect(intercepted).toBe(true);
+ const color = await page.evaluate(() => window.getComputedStyle(document.body).backgroundColor);
+ expect(color).toBe('rgb(255, 192, 203)');
+});
diff --git a/tests/page/page-request-fulfill.spec.ts b/tests/page/page-request-fulfill.spec.ts
index abcdb3ffe9..1c594fac29 100644
--- a/tests/page/page-request-fulfill.spec.ts
+++ b/tests/page/page-request-fulfill.spec.ts
@@ -353,3 +353,31 @@ function findResponse(har: har.HARFile, url: string): har.Response {
expect(entry, originalUrl).toBeTruthy();
return entry?.response;
}
+
+it('should fulfill preload link requests', async ({ page, server, browserName }) => {
+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/16745' });
+ it.fixme(browserName === 'webkit', 'Preload requests are aborted in WebKit when interception is enabled');
+ let intercepted = false;
+ await page.route('**/one-style.css', route => {
+ intercepted = true;
+ route.fulfill({
+ status: 200,
+ headers: {
+ 'content-type': 'text/css; charset=utf-8',
+ 'cache-control': 'no-cache, no-store',
+ 'custom': 'value'
+ },
+ body: 'body { background-color: green; }'
+ });
+ });
+ const [response] = await Promise.all([
+ page.waitForResponse('**/one-style.css'),
+ page.goto(server.PREFIX + '/preload.html')
+ ]);
+ expect(await response.headerValue('custom')).toBe('value');
+ await page.waitForFunction(() => (window as any).preloadedStyles);
+ expect(intercepted).toBe(true);
+ const color = await page.evaluate(() => window.getComputedStyle(document.body).backgroundColor);
+ expect(color).toBe('rgb(0, 128, 0)');
+});
+