本质上,我有一块代码在等待,直到特定请求在puppeteer中完成,它看起来像这样:
page.on('response', async (response) => {
const request = response.request();
if (request.url().includes('specificurl.com')){
console.log(response);
}
});
然而,我想添加120000ms的超时,这样,如果在2分钟内没有找到我的特定请求,它就会超时。这可能吗?
任何帮助都将不胜感激!
也许是这样的:
await Promise.race([
new Promise((resolve, _) => {
page.on('response', async (response) => {
const request = response.request();
if (request.url().includes('specificurl.com')) {
console.log(response);
resolve();
}
});
}),
new Promise((_, reject) => {
setTimeout(reject, 120000, new Error('Timeout'));
}),
]);