Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,12 @@ class InterceptableRequest {
// Re-fetching the resource may produce side effects on the server, only
// do it for GETs of static subresources and prefetch requests.
if (request.method() !== 'GET')
return Buffer.from('');
throw new Error('Response body is unavailable for evicted resources');
if (!kRefetchSafeResourceTypes.has(request.resourceType())) {
const rawHeaders = await request.internalRawRequestHeaders();
const isPrefetch = rawHeaders.some(h => h.name.toLowerCase() === 'sec-purpose' && h.value.startsWith('prefetch'));
if (!isPrefetch)
return Buffer.from('');
throw new Error('Response body is unavailable for evicted resources');
}

const resource = await session.send('Network.loadNetworkResource', { url: request.url(), frameId: request.serviceWorker() ? undefined : request.frame()!._id, options: { disableCache: false, includeCredentials: true } });
Expand Down
27 changes: 27 additions & 0 deletions tests/page/page-network-response.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,33 @@ it('should return body for image with evicted body', {
expect(body.toString('base64')).toBe(imageBase64);
});

it('should throw explicit error for fetch()ed resource with evicted body', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42862' },
}, async ({ page, server, browserName }) => {
const bodyBuffer = Buffer.alloc(50000, 0x50);
server.setRoute('/export', (req, res) => {
res.writeHead(200, { 'Content-Type': 'application/octet-stream', 'Content-Length': String(bodyBuffer.length) });
res.end(bodyBuffer);
});
await page.goto(server.EMPTY_PAGE);
const [response] = await Promise.all([
page.waitForResponse(r => r.url().includes('/export')),
page.evaluate(async () => {
const response = await fetch('/export');
const blob = await response.blob();
(window as any).__blobSize = blob.size;
}),
]);
expect(await page.evaluate(() => (window as any).__blobSize)).toBe(50000);

if (browserName !== 'chromium') {
expect((await response.body()).length).toBe(50000);
} else {
const error = await response.body().catch(e => e);
expect(error.message).toContain('Response body is unavailable for evicted resources');
}
});

it('should bypass disk cache when page interception is enabled', async ({ page, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30000' });
await page.goto(server.PREFIX + '/frames/one-frame.html');
Expand Down