为什么Puppeteer-firefox在服务器上不起作用?

时间:2019-12-18 21:29:14

标签: javascript node.js puppeteer

我正在尝试在Windows Server 2008和2016上运行 有什么解决方案可以启动它吗?我搜索了很多,但什么也没找到。 我收到错误消息:

C:\Users\Administrator\Desktop\_t>node app.js
ERROR: The process "1212" not found.
(node:4276) UnhandledPromiseRejectionWarning: Error: Failed to launch Firefox!


    at onClose (C:\Users\Administrator\Desktop\_t\node_modules\puppeteer-firefox
\lib\Launcher.js:263:14)
    at Interface.helper.addEventListener (C:\Users\Administrator\Desktop\_t\node
_modules\puppeteer-firefox\lib\Launcher.js:252:50)
    at Interface.emit (events.js:187:15)
    at Interface.close (readline.js:379:8)
    at Socket.onend (readline.js:157:10)
    at Socket.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1094:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  -- ASYNC --
    at Puppeteer.<anonymous> (C:\Users\Administrator\Desktop\_t\node_modules\pup
peteer-firefox\lib\helper.js:31:27)
    at C:\Users\Administrator\Desktop\_t\a.js:253:21
    at afterLogin (C:\Users\Administrator\Desktop\_t\a.js:277:4)
    at Object.start (C:\Users\Administrator\Desktop\_t\a.js:101:2)
    at Object.<anonymous> (C:\Users\Administrator\Desktop\_t\app.js:156:7)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:282:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
(node:4276) 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:4276) [DEP0018] DeprecationWarning: Unhandled promise rejections are depre
cated. In the future, promise rejections that are not handled will terminate the
 Node.js process with a non-zero exit code.

在Ubuntu服务器上:

(node:7869) UnhandledPromiseRejectionWarning: Error: Failed to launch Firefox!


    at onClose (/root/node_modules/puppeteer-firefox/lib/Launcher.js:263:14)
    at Interface.helper.addEventListener (/root/node_modules/puppeteer-firefox/lib/Launcher.js:252:50)
    at Interface.emit (events.js:194:15)
    at Interface.close (readline.js:379:8)
    at Socket.onend (readline.js:157:10)
    at Socket.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1103:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  -- ASYNC --
    at Puppeteer.<anonymous> (/root/node_modules/puppeteer-firefox/lib/helper.js:31:27)
    at /root/a.js:255:21
    at afterLogin (/root/a.js:269:4)
    at Object.start (/root/a.js:102:2)
    at Object.<anonymous> (/root/app.js:156:7)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
(node:7869) 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:7869) [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.

它至少可以在某些服务器上运行吗? 在我的台式计算机上一切正常。

需要使用Firefox的版本 Puppeteer-firefox

2 个答案:

答案 0 :(得分:0)

我在VPS Windows上遇到了相同的问题(无法启动Firefox)。

所以我去了 node_modules / puppeteer-firefox / .local-browser /.../ firefox.exe ,我试图打开它。尝试打开exe文件时出现 0xc00007b错误

下载适用于Windows的“一次全部运行”,然后开始安装所有软件。我做了这个,这对我有用。 试试看,告诉我!

编辑:(对不起的英语不好)

答案 1 :(得分:0)

请不要再使用puppeteer-firefox软件包。已弃用。
官方puppeteer包中现已包含对Firefox的实验性支持。

有关如何在Firefox上运行脚本的信息,这里为example from the Puppeteer repository

(async () => {
  const browser = await puppeteer.launch(firefoxOptions);

  const page = await browser.newPage();
  console.log(await browser.version());

  await page.goto('https://news.ycombinator.com/');

  // Extract articles from the page.
  const resultsSelector = '.storylink';
  const links = await page.evaluate((resultsSelector) => {
    const anchors = Array.from(document.querySelectorAll(resultsSelector));
    return anchors.map((anchor) => {
      const title = anchor.textContent.trim();
      return `${title} - ${anchor.href}`;
    });
  }, resultsSelector);
  console.log(links.join('\n'));

  await browser.close();
})();

如果启动Firefox仍存在问题,请告知我们,我们将其修复。