Such option is available in normal mode using Chrome DevTools (Sources>Overrides).
I am trying to find the corresponding command line parameter in switches list, but with no success so far.
How can I launch headless Chrome with local overrides directory in Puppeteer?
I cannot find a direct way to do it, and it is not mentioned in the Chrome DevTools Protocol either. However, you can intercept your requests to achieve it, and probably do it more flexibly. Here is an example for overriding a single file:
const data = fs.readFileSync('/path/to/my/file.js', 'utf-8');
await page.setRequestInterception(true);
page.on('request', interceptedRequest => {
if (interceptedRequest.url() === 'https://www.google.com/file.js') {
interceptedRequest.respond({
body: data
});
} else {
interceptedRequest.continue();
}
});
(The response object passed to respond is described here)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With