Closed BeejeeDS closed 10 months ago
I tried the following which works for me, what am I doing different?
import { chromium } from 'playwright';
(async () => {
const browser = await chromium.launch({
headless: false,
});
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://example.com');
await page.route('**/foo.pdf', async route => {
await route.fulfill({
contentType: 'text/csv',
headers: {
'Content-Disposition': 'inline; filename=test.csv'
},
body: 'This is a test'
}
);
});
console.log('Received download: ' + JSON.stringify(await page.evaluate(() => fetch('https://example.com/foo.pdf').then(r => ([...r.headers.entries()])))));
// Teardown
await context.close();
await browser.close();
})();
@mxschmitt I've added your example to my project but the result stays the same, there are 2 headers (content-length and content-type) but no content-disposition header.
I've added my playwright.config to my original message.
This is the test I've created based on your code sample:
test('Mxschmitt test.', async () => {
const browser = await chromium.launch({
headless: false,
});
const context = await browser.newContext();
const page = await context.newPage();
await page.route('**/foo.pdf', async route => {
await route.fulfill({
contentType: 'text/csv',
headers: {
'Content-Disposition': 'inline; filename=test.csv'
},
body: 'This is a test'
}
);
});
// @ts-ignore
console.log('Received download: ' + JSON.stringify(await page.evaluate(() => fetch('https://example.com/foo.pdf').then(r => ([...r.headers.entries()])))));
// Returns Received download: [["content-length","14"],["content-type","text/csv"]]
// Teardown
await context.close();
await browser.close();
});`
If you do await page.goto('https://example.com');
before the page.route, it works as intended. Would that work for you? Seems like something what Chromium is internally doing.
Closing as per above. Please re-file for further bug reports / feature requests.
System info
Source code
Expected
I expect the
content-type
andcontent-disposition
headers to be present in the response.Actual
The response doesn't contain the
content-disposition
header, onlycontent-type
is present.Playwright config