The main problem is when intercepting a navigation request (e.g. a link to a page points or redirects to a pdf or another type of document we don't want to).
For example a simple approach:
// Enable request interceptions
await page.setRequestInterception(true);
// do not load images and fonts
await page.on("request", (request) => {
if (request.isInterceptResolutionHandled()) return;
if (request.isNavigationRequest())
request.abort("blockedbyclient");
else
request.continue();
});
Or intercepting the response:
const client = await page.createCDPSession();
const cTypeHeader = "content-type";
const cTypeExp = /\bhtml\b/i;
const errorReason = "BlockedByClient";
// intercept request when response headers were received
await client.send('Fetch.enable', {
patterns: [{ urlPattern: '*', resourceType: 'Document', requestStage: 'Response' }],
});
await client.on('Fetch.requestPaused', async evt => {
const requestId = evt.requestId;
const status = evt.responseStatusCode;
if (status >= 200 && status <= 299) {
const headers = evt.responseHeaders || [];
const contentType = headers.find(h => h.name.toLowerCase() == cTypeHeader)?.value;
// Do not allow anything other than html document.
if (contentType && !cTypeExp.test(contentType))
return await client.send('Fetch.failRequest', { requestId, errorReason }).catch(none);
}
await client.send('Fetch.continueRequest', { requestId }).catch(none);
});
Both lead to the same situation when the browser kills the renderer and occasionally dies as they are in a single process 😀
The bug report is here and I was about to submit one more with crbug.com. But was also wondering if it is possible to run chromium without the --single-process flag. I tried just removing the flag but didn't have much success so far.
This is rather a question, not a bug report.
The main problem is when intercepting a navigation request (e.g. a link to a page points or redirects to a pdf or another type of document we don't want to).
For example a simple approach:
Or intercepting the response:
Both lead to the same situation when the browser kills the renderer and occasionally dies as they are in a single process 😀
The bug report is here and I was about to submit one more with crbug.com. But was also wondering if it is possible to run chromium without the
--single-process
flag. I tried just removing the flag but didn't have much success so far.