[Question] Observing preflight OPTIONS network requests
I'm working on some tests that want to look at the timings of network requests and am interested in recording the timing for the preflight request. When I run the a script like this in under debug mode and open the browser dev tools, I see the OPTIONS request being made

But when I setup a page.route() or page.on('requestfinished') listener, I am not able to observe the preflight call, only the GET request. Is there a special flag that I am missing in how the browser is launched that would allow me to view that data?
const playwright = require('playwright');
(async () => {
const browser = await playwright.webkit.launch();
const context = await browser.newContext();
const page = await context.newPage();
// Log and continue all network requests
page.route('**', (route, request) => {
console.log(`page.route: ${request.method()}, ${request.url()}`);
route.continue();
});
page.on('requestfinished', (request) => {
console.log(`requestfinished: ${request.method()} ${request.url()}`);
console.dir(request.timing());
});
const response = await page.evaluate(async () => {
const resp = await window.fetch('https://httpbin.org/get', {
method: 'GET',
headers: {
'x-custom': 'true',
}
});
return resp.json();
});
await browser.close();
})();
We don't currently fire network events in playwright for the preflight requests. Do you need it across all browsers? Asking because in Chromium we receive them from the browser and as a temp workaround you can listen to them via bare CDP proocol.
Thanks for the pointer on using the CDP protocol. I don’t need cross browser support for these tests, so this should work.
Closing as per above, please feel free to open a new issue if this does not cover your use case.