gpt4 book ai didi

javascript - UnhandledPromiseRejectionWarning : Error: Protocol error (Runtime. callFunctionOn) : Target closed. (Puppeteer)

转载 作者:行者123 更新时间:2023-12-03 01:45:52 26 4
gpt4 key购买 nike

我是 Puppeteer 和 Node 的新手,在尝试执行以下代码时收到此错误:

'use strict';

const puppeteer = require('puppeteer');
const evalLib = require('./oaa_a11y_evaluation.js');

function evaluateRules() {
var ruleset = OpenAjax.a11y.RulesetManager.getRuleset("ARIA_STRICT");
var evaluator_factory = OpenAjax.a11y.EvaluatorFactory.newInstance();
evaluator_factory.setParameter('ruleset', ruleset);
evaluator_factory.setFeature('eventProcessing', 'fae-util');
evaluator_factory.setFeature('groups', 7);
var evaluator = evaluator_factory.newEvaluator();
var evaluation = evaluator.evaluate(window.document, document.title, document.location.href);
// var out = evaluation.toJSON(true);
return;
}

(async() => {
const browser = await puppeteer.launch();
var page = await browser.newPage();
await page.goto('http://mihirkumar.com/', {waitUntil: 'load'});
page.evaluate(evaluateRules);
await browser.close();
})();

以下是错误消息的详细信息:

(node:27876) UnhandledPromiseRejectionWarning: Error: Protocol error (Runtime.callFunctionOn): Target closed.
at Promise (C:\Users\Mihir\fae\node_modules\puppeteer\lib\Connection.js:200:56)
at new Promise (<anonymous>)
at CDPSession.send (C:\Users\Mihir\fae\node_modules\puppeteer\lib\Connection.js:199:12)
at ExecutionContext.evaluateHandle (C:\Users\Mihir\fae\node_modules\puppeteer\lib\ExecutionContext.js:79:75)
at ExecutionContext.evaluate (C:\Users\Mihir\fae\node_modules\puppeteer\lib\ExecutionContext.js:46:31)
at Frame.evaluate (C:\Users\Mihir\fae\node_modules\puppeteer\lib\FrameManager.js:326:20)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:27876) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:27876) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

来自 https://github.com/GoogleChromeLabs/puppeteer-examples 的其他示例运行得很好,所以我不相信我需要使用提到的修复here 。感谢您的帮助。

最佳答案

正如 Sven 在评论中提到的,您应该使用 awaitpage在关闭浏览器之前返回一个 promise (几乎是所有 promise )的函数。

试试这个:

'use strict';

const puppeteer = require('puppeteer');
const evalLib = require('./oaa_a11y_evaluation.js');

async function evaluateRules() {
var ruleset = OpenAjax.a11y.RulesetManager.getRuleset("ARIA_STRICT");
var evaluator_factory = OpenAjax.a11y.EvaluatorFactory.newInstance();
evaluator_factory.setParameter('ruleset', ruleset);
evaluator_factory.setFeature('eventProcessing', 'fae-util');
evaluator_factory.setFeature('groups', 7);
var evaluator = evaluator_factory.newEvaluator();
var evaluation = evaluator.evaluate(window.document, document.title, document.location.href);
// var out = evaluation.toJSON(true);
return;
}

(async() => {
const browser = await puppeteer.launch();
var page = await browser.newPage();
await page.goto('http://mihirkumar.com/', {waitUntil: 'load'});
await page.evaluate(evaluateRules); // <-- await here
await browser.close();
})();

关于javascript - UnhandledPromiseRejectionWarning : Error: Protocol error (Runtime. callFunctionOn) : Target closed. (Puppeteer),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50645321/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com