stackblitz / webcontainer-core

Dev environments. In your web app.
https://webcontainers.io
MIT License
3.94k stars 173 forks source link

Playwright is not working #247

Open spidy0x0 opened 3 years ago

spidy0x0 commented 3 years ago

Describe the bug: Playwright is a browser automation tool . but its failing on startup

Steps to reproduce:

  1. Go to https://stackblitz.com/edit/http-server-wj3c6q

Expected behavior: Open browser interface

Desktop :

Additional context:

npm install && npx playwright open

warn preInstall No description field
warn preInstall No repository field
warn preInstall No license field
┌ [1/3] 🔍  Resolving dependencies
└ Completed in 2.56s
┌ [2/3] 🚚  Fetching dependencies
└ Completed in 13.006s
┌ [3/3] 🔗  Linking dependencies
└ Completed in 2.566s
info security We found `install` scripts which turbo skips for security reasons. For
more information see https://turbo.sh/install-scripts.
├─ nodemon@2.0.12
└─ playwright@1.12.3

success Saved lockfile "package-lock.json"
success Updated "package.json"

success Install finished in 18.773s
browserType.launch: Failed to launch chromium because executable doesn't exist at /home/.cache/ms-playwright/chromium-888113/chrome-linux/chrome
Try re-installing playwright with "npm install playwright"
Error
    at Object.captureStackTrace (/home/projects/http-server-wj3c6q/node_modules/playwright/lib/utils/stackTrace.js:51:19)
    at Connection.sendMessageToServer (/home/projects/http-server-wj3c6q/node_modules/playwright/lib/client/connection.js:73:48)
    at Proxy.eval (/home/projects/http-server-wj3c6q/node_modules/playwright/lib/client/channelOwner.js:64:61)
    at eval (/home/projects/http-server-wj3c6q/node_modules/playwright/lib/client/browserType.js:59:67)
    at BrowserType._wrapApiCall (/home/projects/http-server-wj3c6q/node_modules/playwright/lib/client/channelOwner.js:77:34)
    at BrowserType.launch (/home/projects/http-server-wj3c6q/node_modules/playwright/lib/client/browserType.js:50:21)
    at launchContext (/home/projects/http-server-wj3c6q/node_modules/playwright/lib/cli/cli.js:313:39)
    at open (/home/projects/http-server-wj3c6q/node_modules/playwright/lib/cli/cli.js:401:62)
    at Command.eval (/home/projects/http-server-wj3c6q/node_modules/playwright/lib/cli/cli.js:84:5)
    at Command.listener [as _actionHandler] (/home/projects/http-server-wj3c6q/node_modules/commander/index.js:426:31)
    at Command._parseCommand (/home/projects/http-server-wj3c6q/node_modules/commander/index.js:1002:14)
    at Command._dispatchSubcommand (/home/projects/http-server-wj3c6q/node_modules/commander/index.js:953:18)
    at Command._parseCommand (/home/projects/http-server-wj3c6q/node_modules/commander/index.js:970:12)
    at Command.parse (/home/projects/http-server-wj3c6q/node_modules/commander/index.js:801:10)
    at Object.eval (/home/projects/http-server-wj3c6q/node_modules/playwright/lib/cli/cli.js:284:25)
    at Object.function (https://http-server-wj3c6q.jw.staticblitz.com/blitz.e6adaf772b18819f7b4ab8325b73d63276acda8f.js:11:169884)
    at Module._compile (https://http-server-wj3c6q.jw.staticblitz.com/blitz.e6adaf772b18819f7b4ab8325b73d63276acda8f.js:6:188591)
    at Object.Module._extensions..js (https://http-server-wj3c6q.jw.staticblitz.com/blitz.e6adaf772b18819f7b4ab8325b73d63276acda8f.js:6:188950)
    at Module.load (https://http-server-wj3c6q.jw.staticblitz.com/blitz.e6adaf772b18819f7b4ab8325b73d63276acda8f.js:6:187030)
    at Function.Module._load (https://http-server-wj3c6q.jw.staticblitz.com/blitz.e6adaf772b18819f7b4ab8325b73d63276acda8f.js:6:184608)
    at Function.executeUserEntryPoint [as runMain] (https://http-server-wj3c6q.jw.staticblitz.com/blitz.e6adaf772b18819f7b4ab8325b73d63276acda8f.js:6:701476)
    at Object.a0_0x3b27 (https://http-server-wj3c6q.jw.staticblitz.com/blitz.e6adaf772b18819f7b4ab8325b73d63276acda8f.js:6:1124537)
    at _0x11423c (https://http-server-wj3c6q.jw.staticblitz.com/blitz.e6adaf772b18819f7b4ab8325b73d63276acda8f.js:8:23471)
    at _0x364f83 (https://http-server-wj3c6q.jw.staticblitz.com/blitz.e6adaf772b18819f7b4ab8325b73d63276acda8f.js:11:42279)
    at _0xaf685b (https://http-server-wj3c6q.jw.staticblitz.com/blitz.e6adaf772b18819f7b4ab8325b73d63276acda8f.js:11:262621)
    at Object.run (https://http-server-wj3c6q.jw.staticblitz.com/blitz.e6adaf772b18819f7b4ab8325b73d63276acda8f.js:11:261772)

Also, https://turbo.sh/install-scripts is not working

thescientist13 commented 3 years ago

It looks like Playright needs to execute pre (or post) install scripts, which aren't supported in Stackblitz.

SamVerschueren commented 3 years ago

Hi @spidyhackx! This will not just work out of the box. The problem here is that in order to run Playwright, or even Puppeteer, you need a binary that will not just work in the browser. We can't just execute any arbitrary binary in WebContainer as everything still runs in the browser.

We are looking at possible solutions to get something like Puppeteer/Playwright working within StackBlitz, but we are not there yet and it's still ideas, so no active development on that front yet.

ndom91 commented 2 years ago

Hi together, I've been tinkering with this, and seem to have gotten a bit further, but chromium still times out on launching for me.

I'm using chrome-aws-lambda and playwright-core. After installing these dependencies, there will be a google-chrome binary in /usr/local/bin/. If yuo manually specify that as the executablePath argument, you'll get past the issue mentioned in the OP.

The problem then becomes one of chromium seemingly timing out on launching. I've messed with a few chromium flags, but to no avail.

Playwright / Chromium Setup ```js const chromium = require("chrome-aws-lambda") const playwright = require("playwright-core") console.log(`Hello Node.js v${process.versions.node}!`) const main = async () => { try { chromium.args.push("--enable-logging=stderr") chromium.args.push("--log-level=0") const browser = await playwright.chromium.launch({ args: chromium.args, executablePath: "/usr/local/bin/google-chrome", headless: true, ignoreHTTPSErrors: true, }) ... ```
Log Output ```js ~/projects/node-riv6gt ❯ node index.js Hello Node.js v14.16.0! browserType.launch: Timeout 30000ms exceeded. =========================== logs =========================== /usr/local/bin/google-chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,AcceptCHFrame --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --allow-running-insecure-content --autoplay-policy=user-gesture-required --disable-component-update --disable-domain-reliability --disable-features=AudioServiceOutOfProcess,IsolateOrigins,site-per-process --disable-print-preview --disable-setuid-sandbox --disable-site-isolation-trials --disable-speech-api --disable-web-security --disk-cache-size=33554432 --enable-features=SharedArrayBuffer --hide-scrollbars --ignore-gpu-blocklist --in-process-gpu --mute-audio --no-default-browser-check --no-pings --no-sandbox --no-zygote --use-gl=swiftshader --window-size=1920,1080 --start-maximized --user-data-dir=/tmp/playwright_chromiumdev_profile-iWeMcv --remote-debugging-pipe --no-startup-window pid=11 [pid=11] [pid=11] starting temporary directories cleanup [pid=11] finished temporary directories cleanup ============================================================ at main (/home/projects/node-riv6gt/index.js:13:47) at Object.eval (/home/projects/node-riv6gt/index.js:35:1) at Object.function (https://node-riv6gt.w.staticblitz.com/blitz.a3339ebb87d0fe73c7995fe67420660e0dc95de2.js:11:114121) at Module._compile (https://node-riv6gt.w.staticblitz.com/blitz.a3339ebb87d0fe73c7995fe67420660e0dc95de2.js:6:167880) at Object.Module._extensions..js (https://node-riv6gt.w.staticblitz.com/blitz.a3339ebb87d0fe73c7995fe67420660e0dc95de2.js:6:168239) at Module.load (https://node-riv6gt.w.staticblitz.com/blitz.a3339ebb87d0fe73c7995fe67420660e0dc95de2.js:6:166317) at Function.Module._load (https://node-riv6gt.w.staticblitz.com/blitz.a3339ebb87d0fe73c7995fe67420660e0dc95de2.js:6:163857) at Function.executeUserEntryPoint [as runMain] (https://node-riv6gt.w.staticblitz.com/blitz.a3339ebb87d0fe73c7995fe67420660e0dc95de2.js:6:694728) at Object.a0_0x181b (https://node-riv6gt.w.staticblitz.com/blitz.a3339ebb87d0fe73c7995fe67420660e0dc95de2.js:6:1257523) at _0x3fd9e9 (https://node-riv6gt.w.staticblitz.com/blitz.a3339ebb87d0fe73c7995fe67420660e0dc95de2.js:8:26340) at _0x59d6ad (https://node-riv6gt.w.staticblitz.com/blitz.a3339ebb87d0fe73c7995fe67420660e0dc95de2.js:11:59472) at _0x403d38 (https://node-riv6gt.w.staticblitz.com/blitz.a3339ebb87d0fe73c7995fe67420660e0dc95de2.js:11:352922) at Object.run (https://node-riv6gt.w.staticblitz.com/blitz.a3339ebb87d0fe73c7995fe67420660e0dc95de2.js:11:352022) { name: 'TimeoutError' } ``` > The timeout stacktrace is pointing to the `const browser = await playwright.chromium.launch({` line

For more details, see: https://stackblitz.com/edit/node-riv6gt?file=index.js