【问题标题】:Unable to launch webkit or take a screenshot with playwright无法启动 webkit 或与 playwright 截屏
【发布时间】:2021-05-09 07:08:12
【问题描述】:

但它适用于铬。

剧作家:1.8.0 节点:14.15 Ubuntu:20.04

这是我的代码。

const playwright = require("playwright");

(async () => {
  for (const browserType of ["chromium", "firefox", "webkit"]) {
    const browser = await playwright[browserType].launch();
    const context = await browser.newContext();
    const page = await context.newPage();
    await page.goto("http://whatsmyuseragent.org/");
    await page.screenshot({ path: `example-${browserType}.png` });
    await browser.close();
  }
})();

【问题讨论】:

  • 它有什么作用?有哪些错误消息?

标签: automation playwright playwright-python


【解决方案1】:

我解决了我错过了这个库 libgstreamer-plugins-bad1.0-0:am​​d64

【讨论】:

    【解决方案2】:

    在 ubuntu 20.04 上,我在运行我的第一个剧本时遇到了错误: node first_script.js 安装后通过npm i -D playwright(playwright v1.10.0 和 v10.19.0)每playwright install instructions

        const { webkit } = require('playwright');
    
        (async () => {
          const browser = await webkit.launch();
          const page = await browser.newPage();
          await page.goto('http://whatsmyuseragent.org/');
          await page.screenshot({ path: `whatsmyuseragent.png` });
          await browser.close();
        })();
    

    看到的错误包括:

    • “加载共享库时出错:libharfbuzz-icu.so.0:无法打开共享对象文件:没有这样的文件或目录”

    根据几个错误#1935#2621,运行以下命令让我成功运行:

    sudo apt-get install libgles2 gstreamer1.0-libav libharfbuzz-icu0 libwoff1 libgstreamer-plugins-bad1.0-0 libgstreamer-gl1.0-0 libwebp-dev

    然后尝试在同一 ubuntu 20.04 node second_script.js 上使用 chrome(chromium)、firefox 和 webkit 运行第二个脚本

    const playwright = require('playwright');
    
    (async () => {
      for (const browserType of ['chromium', 'firefox', 'webkit']) {
        const browser = await playwright[browserType].launch();
        const context = await browser.newContext();
        const page = await context.newPage();
        await page.goto('http://whatsmyuseragent.org/');
        await page.screenshot({ path: `example-${browserType}.png` });
        await browser.close();
      }
    })();
    

    得到错误:

    • [pid=532053][err] 文件 /home/playwright/.cache/ms-playwright/firefox-1238/firefox/libxul.so 的 XPCOMGlueLoad 错误: [pid=532053][err] libdbus-glib-1.so.2:无法打开共享对象文件:没有这样的文件或目录 [pid=532053][err] 无法加载 XPCOM。

    安装的 firefox 和第二个脚本运行成功:

    sudo apt-get install firefox
    

    【讨论】:

      猜你喜欢
      • 2021-07-09
      • 1970-01-01
      • 2021-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-29
      • 1970-01-01
      • 2020-10-03
      相关资源
      最近更新 更多