There was a answer about how to resolve blob download, the link as follow. How to intercept downloads of blob generated in client side of website through puppeteer?
But I want to intercept those requests which initator was script in browser. It seems that this request is blob type. The image as follows:
When following above example, the blob request did not intercept, so how do I intercept this request?
My code as follow:
import {Browser, connect, Page} from "puppeteer";
(async () => {
const browser = await connect({
browserURL: `http://127.0.0.1:4444`,
ignoreHTTPSErrors: true,
});
const page = await this.browser.newPage();
await page.setRequestInterception(true);
page.on("request", async res => {
// do somethings
});
page.on("response", async res => {
// do somethings
});
const cdp = await page.target().createCDPSession();
await cdp.send('Page.setDownloadBehavior', {
behavior: 'allow',
downloadPath: './'
});
// there is no download, it means that blob request don't intercept
await cdp.on('Page.downloadWillBegin', ({ url, suggestedFilename }) => {
// do somethins;
});
// there is no download
await cdp.on('Page.downloadProgress', ({ state }) => {
if (state === 'completed') {
// do somethins;
}
});
const url = `https://amap.com`;
await page.goto(url);
})()
