我正在拦截页面请求,我想等待特殊请求20秒钟,然后该回复请求结束?
```node.js
page.on('response',async (response)=>{
if(response.url().endWith('whatever'){
x=response.status===200
}
```
答案 0 :(得分:1)
在我的情况下,我使用promise,我等待一个promise,该promise在其内部拦截请求,无论如何要解决,直到20在下面看到我的代码
let response_received=await new Promise((resolve,reject)=>{
page.on('response',async (response)=>{
if (response.url().endsWith('quickDailySalesReport')){
console.log(response);
if ( response.status()===200){
await sleep(2000);
resolve(true)
}
}
});
setTimeout(()=>resolve(false),20000)
});
console.log(response_received);
if (response_received){//do something}
答案 1 :(得分:0)
page.on('response',async (response)=>{
await sleep(20000);
if(response.url().endWith('whatever')){
x=response.status===200
}
})