UnhandledPromiseRejectionWarning:错误:协议错误(Runtime.callFunctionOn):目标已关闭. (木偶) [英] UnhandledPromiseRejectionWarning: Error: Protocol error (Runtime.callFunctionOn): Target closed. (Puppeteer)

查看:722
本文介绍了UnhandledPromiseRejectionWarning:错误:协议错误(Runtime.callFunctionOn):目标已关闭. (木偶)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to Puppeteer and Node and I get this error when trying to execute the following code:

'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();
})();

以下是详细的错误消息:

Here's the error message in full detail:

(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 中的其他示例非常好,所以我不认为我需要使用提到的修补程序这里.感谢您的帮助.

Other examples from https://github.com/GoogleChromeLabs/puppeteer-examples run perfectly fine so I don't believe I need to use the fixes mentioned here. Thanks for the help.

推荐答案

感谢您的答复.使功能异步肯定是一个更好的改变.我的问题是我没有将OpenAjax javascript库注入已加载的页面.一旦我使用puppeteer的page.addScriptTag函数做到了,一切就可以正常工作.

Thanks for the responses. Making the function async is definitely a change for the better. My problem was that I wasn't injecting the OpenAjax javascript libraries into the loaded page. Once I did that with puppeteer's page.addScriptTag function things worked just fine.

这篇关于UnhandledPromiseRejectionWarning:错误:协议错误(Runtime.callFunctionOn):目标已关闭. (木偶)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆