我有一个综合监测测试一直运行良好。我添加了一些代码来阻止第三方广告跟踪和分析脚本,以加快测试(而不是倾斜分析),就像这里建议的那样:https://scrapingant.com/blog/block-requests-playwright。
在每个测试的顶部,我得到了这样的信息:
await page.route('**/*', filterResources)filterResources方法的定义如下:
const DOMAIN_EXCLUSIONS = [
'connect.facebook.net',
'px.ads.linkedin.com',
[...]
]
module.exports = (route) => {
let matches = DOMAIN_EXCLUSIONS.filter((domain) => {
return route.request().url().startsWith('https://' + domain)
})
return matches.length ? route.abort() : route.continue()
}现在偶尔会引发以下错误,并且测试失败:
route.continue: Target page, context or browser has been closed这种情况可能每6-8次就发生一次。
这是因为页面在某些请求仍未执行时就会导航,因为剧作家认为页面已经完全加载了吗?我正在使用适当的等待,而且测试以前很好。
发布于 2022-02-22 08:36:06
我现在正在抓住并解决这个承诺,这个问题似乎不再发生了:
if (matches.length) {
return route.abort()
}
return route.continue().catch(() => {})https://stackoverflow.com/questions/71191351
复制相似问题