首页 > 解决方案 > 从 Puppeteer 启动 Chromium 在某台机器上超时 - TimeoutError: waiting for target failed: timeout 30000ms exceeded

问题描述

运行 Puppeteer 并启动 Chromium 时出现以下错误。此外,Chromium 作为崩溃页面打开。我无法从打开的窗口导航到任何 URL。

令人惊讶的是,我仅在从某台机器(在我的公司网络中)运行时才会收到此错误。当从我公司网络中的另一台机器以及我的笔记本电脑上运行时,它运行良好。

环顾四周,我注意到建议添加ignoreDefaultArgs: [ '--disable-extensions' ] }到配置中,我这样做了,但仍然收到相同的错误。你对我所缺少的有什么建议吗?

错误信息如下

LOG >> -- START PUPPY --
(node:12008) UnhandledPromiseRejectionWarning: TimeoutError: waiting for target failed: timeout 30000ms exceeded
    at Object.waitWithTimeout (C:\Users\afhassan\Puppy\node_modules\puppeteer\lib\cjs\puppeteer\common\helper.js:224:26)
    at Browser.waitForTarget (C:\Users\afhassan\Puppy\node_modules\puppeteer\lib\cjs\puppeteer\common\Browser.js:269:45)
    at ChromeLauncher.launch (C:\Users\afhassan\Puppy\node_modules\puppeteer\lib\cjs\puppeteer\node\Launcher.js:100:27)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:12008) 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:12008) [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.

错误是由这一行引起的

this._browser = await launch(CONFIG.launchOptions);

launch从 Puppeteer 导入

import {
    Browser,
    Page,
    launch,
    CDPSession
} from 'puppeteer';

我的配置如下

{ verbose: true,
  launchOptions: { headless: false },
  defaultViewPort: { width: 1920, height: 1080 },
  domain: 'domain.com',
  mySiteDomain: 'domain.com',
  users:
   { admin:
      { username: 'myusername',
        password: 'mypassword' },
     user0:
      { username: 'myusername',
        password: 'mypassword' } },
  tests: [ 'NameOfTest' ],
  ignoreDefaultArgs: [ '--disable-extensions' ] }

我的 package.json 的相关部分如下

"dependencies": {
    "puppeteer": "^5.5.0",
    "yargs": "^15.4.1"
  },
  "devDependencies": {
    "@types/puppeteer": "^5.4.2",
    "@types/yargs": "^15.0.11",
    "babel-cli": "^6.26.0",
    "babel-preset-es2015": "^6.24.1",
  }

标签: google-chromeautomated-testspuppeteerchromium

解决方案


推荐阅读