简体   繁体   中英

Unable to launch webkit or take a screenshot with playwright

But it works with chromium.

playwright: 1.8.0 node: 14.15 Ubuntu: 20.04

this is my code.

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

I solved it I was missing this library libgstreamer-plugins-bad1.0-0:amd64

On ubuntu 20.04, I was getting errors when running my first playwright script: node first_script.js after installing via npm i -D playwright (playwright v1.10.0 and v10.19.0) per 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();
    })();

saw errors that included:

  • "error while loading shared libraries: libharfbuzz-icu.so.0: cannot open shared object file: No such file or directory"

Per several bugs #1935 #2621 , running the following allowed me to run successfully:

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

then tried to run 2nd script with chrome(chromium), firefox and webkit on same ubuntu 20.04 node second_script.js

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

and got errors:

  • [pid=532053][err] XPCOMGlueLoad error for file /home/playwright/.cache/ms-playwright/firefox-1238/firefox/libxul.so: [pid=532053][err] libdbus-glib-1.so.2: cannot open shared object file: No such file or directory [pid=532053][err] Couldn't load XPCOM.

installed firefox and 2nd script ran successfully:

sudo apt-get install firefox

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM