Puppeteer:ProtocolError:等待选择器失败:协议错误:参数应与目标对象属于同一个JavaScript



我创建了这个函数:

async function sendRequest(page: Page, url: string) {
await Promise.all([
page.waitForNavigation(),
page.goto(url),
page.waitForSelector("div#header"),
]);
}

当我使用这个函数时,NodeJS会抛出以下错误消息:

ProtocolError: Waiting for selector `div#header` failed: Protocol error (Runtime.callFunctionOn): Argument should belong to the same JavaScript world as target object
at /home/mble/Code/repos/pluget/services/spigotScraper/node_modules/puppeteer-core/src/common/Connection.ts:400:16
at new Promise (<anonymous>)
at CDPSessionImpl.send (/home/mble/Code/repos/pluget/services/spigotScraper/node_modules/puppeteer-core/src/common/Connection.ts:396:12)
at ExecutionContext._ExecutionContext_evaluate (/home/mble/Code/repos/pluget/services/spigotScraper/node_modules/puppeteer-core/src/common/ExecutionContext.ts:274:44)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at WaitTask.rerun (/home/mble/Code/repos/pluget/services/spigotScraper/node_modules/puppeteer-core/src/common/WaitTask.ts:123:26)
[ERROR] 18:53:05 ProtocolError: Waiting for selector `div#header` failed: Protocol error (Runtime.callFunctionOn): Argument should belong to the same JavaScript world as target object

我该如何解决这个问题?

Ahoj Macieji,我也在额外使用木偶师,但我不确定这是否是原因。然而,错误与您的情况相同:

参数应该与目标对象属于同一个JavaScript世界

这种情况发生在page.goto运行后,设置page.waitForSelector,然后进行导航(例如,在我的情况下,从身份验证页面(。我想这会导致";不同的Javascript世界";,并且该错误被触发。

对我来说,一个变通办法是先使用page.waitForSelector,然后使用page.goto。很奇怪,但我希望它也适用于你。

相关内容

  • 没有找到相关文章

最新更新