Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to run Playwright browser automtation library #2492

Closed
alexkreidler opened this issue Mar 27, 2023 · 36 comments
Closed

Fails to run Playwright browser automtation library #2492

alexkreidler opened this issue Mar 27, 2023 · 36 comments
Labels
atw bug Something isn't working

Comments

@alexkreidler
Copy link

What version of Bun is running?

0.5.8

What platform is your computer?

Linux 5.4.0-132-generic x86_64 x86_64 (Ubuntu 20.04.5 LTS)

What steps can reproduce the bug?

I put the classic Playwright example in testPlaywright.ts:

import { chromium, devices } from 'playwright';
import assert from 'node:assert';

(async () => {
  // Setup
  const browser = await chromium.launch();
  const context = await browser.newContext(devices['iPhone 11']);
  const page = await context.newPage();

  // The actual interesting bit
  await context.route('**.jpg', route => route.abort());
  await page.goto('https://example.com/');

  assert(await page.title() === 'Example Domain'); // 👎 not a Web First assertion

  // Teardown
  await context.close();
  await browser.close();
})()
$ bun ./src/testPlaywright.ts
[0.01ms] ".env"
47 |     const e = new _errors.TimeoutError(error.error.message);
48 |     e.stack = error.error.stack || '';
49 |     return e;
50 |   }
51 |   const e = new Error(error.error.message);
52 |   e.stack = error.error.stack || '';
                     ^
TypeError: undefined is not an object (evaluating 'pipeRead.on')
=========================== logs ===========================
<launching> /home/alex/.cache/ms-playwright/chromium-1048/chrome-linux/chrome --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate --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 --export-tagged-pdf --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-rfjU3y --remote-debugging-pipe --no-startup-window
<launched> pid=1842709
============================================================
      at /project/node_modules/.pnpm/playwright-core@1.31.2/node_modules/playwright-core/lib/protocol/serializers.js:52:18

I get the same error if I rename it to a .js file

What is the expected behavior?

Playwright should run properly.

What do you see instead?

No response

Additional information

Puppeteer has had issues with Bun: #2316

Also puppeteer and playwright depend on the Node TLS API implementation #781 (comment)_

@alexkreidler alexkreidler added the bug Something isn't working label Mar 27, 2023
@infrahead
Copy link

infrahead commented Jul 21, 2023

Was hopeful Bun 0.7 would run my Playwright compatibility tests, but while the process and TLS related-errors (and my workarounds) have gone away, there is some snag seemingly with the import/transpile/node-compat dance taking place...

Given the most basic boilerplate code and trying to init a browser, the imports are undefined

const browser = await webkit.launch()
                          ^
TypeError: undefined is not an object (evaluating 'webkit.launch')

Seems to come from fact that playwright-core is using both index.js and index.mjs together?
see https://github.com/microsoft/playwright/blob/main/packages/playwright-core/index.mjs#L17

exports field looks like: https://github.com/microsoft/playwright/blob/main/packages/playwright-core/package.json#L14

I've tried rearranging the Playwright source code to hack around this but maybe I don't understand what is happening under the hood

@Hebilicious
Copy link

Same error in 0.7.3. Would be great to have this for 1.0 🙏🏽

@infrahead
Copy link

Same error with 0.8.1 and Playwright 1.37.1

@duckception
Copy link

Unfortunately, still an issue with v1.0.0 🥲

@infrahead
Copy link

infrahead commented Sep 10, 2023

To be clear, there are two separate issues that remain here:

  1. The incompatibility with how the playwright and @playwright/test packages do exports (as I commented previously)
  2. The initial bug reported by @alexkreidler also remains as of v1.0.0. If you use one of the browser specific packages (e.g. playwright-chromium) instead, to work around # 1, I still get:
TypeError: launch: launch: undefined is not an object (evaluating 'pipeRead.on')
=========================== logs ===========================
<launching> /home/ewwbun2/.cache/ms-playwright/webkit-1883/pw_run.sh --inspector-pipe --headless --no-startup-window
<launched> pid=1597
============================================================
      at /mnt/c/dev/sdk/bun/node_modules/playwright-core/lib/protocol/serializers.js:52:12

@dreambit
Copy link

same for me((

@hexagon6
Copy link

bun 1.0 and playwright package "@playwright/test": "~1.32" works with running "bun run test" (which runs playwright test testfile.js) in my case.

@infrahead
Copy link

@hexagon6 I'd be curious what the contents of testfile.js are?

@jasongitmail
Copy link

@hexagon6 If I'm not mistaken, you actually need to use bun --bun run test in order for the bun runtime to be used when executing a script command.
(It's a bit confusing; I'd expect the bun runtime to be default unless explicitly overridden with something like --node.)

In this case, adding --bun throws an "intergalactic error" 😆 with @playwright/test 1.37:

Screenshot 2023-09-11 at 12 17 38 PM

Even when bun run test executes successfully.

@infrahead
Copy link

infrahead commented Sep 11, 2023

Ah yes, I wondered about that. I don't believe you need --bun in general case of running scripts, but in this case bun is respecting the node shebang in playwright cli https://github.com/microsoft/playwright/blob/main/packages/playwright/cli.js
so is required to override it

@hexagon6
Copy link

The testfile (actually called routes.test.js):

import { expect, test } from '@playwright/test'

test('about page has expected h1', async ({ page }) => {
  await page.goto('/public/about')
  expect(await page.textContent('h1')).toBe('About this Web App')
})

And I run it like that:

$ bun run test
  $ playwright test tests/routes.test.js

@hexagon6
Copy link

hexagon6 commented Sep 11, 2023

So running with --bun leads to this TypeError message:

TypeError: undefined is not an object (evaluating 'ot._extensions[".js"]')

Full error (which is probably not relevant to this exact issue, but for context):

                                                                    ^
TypeError: undefined is not an object (evaluating 'ot._extensions[".js"]')
      at Pc (/home/user/projects/myproject/node_modules/@playwright/test/lib/utilsBundleImpl.js:16:535)
      at installTransform (/home/user/projects/myproject/node_modules/@playwright/test/lib/common/transform.js:185:24)
      at /home/user/projects/myproject/node_modules/@playwright/test/lib/common/transform.js:158:29 
      at requireOrImport (/home/user/projects/myproject/node_modules/@playwright/test/lib/common/transform.js:157:31)
      at /home/user/projects/myproject/node_modules/@playwright/test/lib/common/configLoader.js:225:15 
      at requireOrImportDefaultObject (/home/user/projects/myproject/node_modules/@playwright/test/lib/common/configLoader.js:224:44)
      at /home/user/projects/myproject/node_modules/@playwright/test/lib/common/configLoader.js:57:25
      at loadConfigFile (/home/user/projects/myproject/node_modules/@playwright/test/lib/common/configLoader.js:55:23)
      at /home/user/projects/myproject/node_modules/@playwright/test/lib/cli.js:127:32
      at processTicksAndRejections (:1:2602)

@iamobj
Copy link

iamobj commented Sep 12, 2023

Actually deno has this problem too, but chromium.connectOverCDP works fine in deno, however I tried chromium.connectOverCDP with bun and it doesn't work either!

@amiruldev20

This comment was marked as duplicate.

@Electroid Electroid added the atw label Sep 14, 2023
@ngocphamm
Copy link

@Electroid Just curious. What does atw label mean? It has no description like most other labels.

@hypertensy
Copy link

@ngocphamm I assume that Access to Work

@infrahead
Copy link

I've learned that Deno also fails to run playwright, and maybe provides some further insight into this problem. Specifically denoland/deno#16899 (comment)

So the child_process shim (which Bun is also abstracting over Bun.spawn) needs to support open fds for stdio[3] and stdio[4] ?

@neoReuters
Copy link

neoReuters commented Oct 4, 2023

FWIW, not sure entirely similar but - having a similar issue with jest here, so might not be exclusive toplaywright.

$ bun --bun run test
$ jest
Test Suites: 0 of 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.085 s
Ran all test suites.
TypeError: undefined is not an object (evaluating 'Module._extensions[".js"]')
    at addHook (/builds/mvp/one/web/node_modules/pirates/lib/index.js:90:41)
    at <anonymous> (/builds/mvp/one/web/node_modules/@jest/transform/build/ScriptTransformer.js:772:12)
    at requireAndTranspileModule (/builds/mvp/one/web/node_modules/@jest/transform/build/ScriptTransformer.js:760:34)
    at <anonymous> (/builds/mvp/one/web/node_modules/@jest/core/build/TestScheduler.js:227:42)
    at processTicksAndRejections (:55:39)
error: script "test" exited with code 1 (SIGHUP)

I switched to happy-dom as the jest testEnvironment and got this error as well:

   Test suite failed to run

    TypeError: Attempted to assign to readonly property.

      at node_modules/jest-runtime/build/index.js:1638:5
      at forEach (:1:21)
      at Object.<anonymous> (node_modules/stack-utils/index.js:35:4)
      at Object.<anonymous> (node_modules/expect/build/toThrowMatchers.js:9:24)
      at Object.<anonymous> (node_modules/expect/build/index.js:23:48)
      at _expect (node_modules/@jest/expect/build/index.js:8:16)
      at createJestExpect (node_modules/@jest/expect/build/index.js:29:3)
      at Object.<anonymous> (node_modules/@jest/expect/build/index.js:39:20)
      at processTicksAndRejections (:55:77)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.277 s
Ran all test suites.

Just putting this here as I feel there might be some overlap.

Solution for now is just to use the native bun test runner which works fine.

@iRyusa
Copy link

iRyusa commented Oct 13, 2023

Bun 1.0.4 Here got another error :

➜  client git:(VNS-30/poc-playwright) ✗ bunx --bun playwright test
213 | // files from packages/playwright*. In production mode, node_modules covers
214 | // that.
215 | const kPlaywrightInternalPrefix = _path.default.resolve(__dirname, '../../../playwright');
216 | const kPlaywrightCoveragePrefix = _path.default.resolve(__dirname, '../../../../tests/config/coverage.js');
217 | function belongsToNodeModules(file) {
218 |   if (file.includes(`${_path.default.sep}node_modules${_path.default.sep}`)) return true;
         ^
TypeError: undefined is not an object (evaluating 'file.includes')
      at belongsToNodeModules (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/transform/compilationCache.js:218:6)
      at shouldTransform (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/transform/transform.js:135:2)
      at resolveHook (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/transform/transform.js:83:7)
      at resolveFilename (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/transform/transform.js:189:23)
      at overridableRequire (:1:20)
      at folderIsModule (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/util.js:276:9)
      at fileIsModule (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/util.js:270:9)
      at /Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/transform/transform.js:168:8
      at requireOrImport (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/transform/transform.js:166:31)
      at /Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/common/configLoader.js:121:15
      at requireOrImportDefaultObject (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/common/configLoader.js:120:44)
      at /Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/common/configLoader.js:94:25
      at loadConfigFile (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/common/configLoader.js:92:23)
      at /Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/cli.js:118:41
      at processTicksAndRejections (:55:76)

@Flynquris
Copy link

Bun 1.0.4 Here got another error :

➜  client git:(VNS-30/poc-playwright) ✗ bunx --bun playwright test
213 | // files from packages/playwright*. In production mode, node_modules covers
214 | // that.
215 | const kPlaywrightInternalPrefix = _path.default.resolve(__dirname, '../../../playwright');
216 | const kPlaywrightCoveragePrefix = _path.default.resolve(__dirname, '../../../../tests/config/coverage.js');
217 | function belongsToNodeModules(file) {
218 |   if (file.includes(`${_path.default.sep}node_modules${_path.default.sep}`)) return true;
         ^
TypeError: undefined is not an object (evaluating 'file.includes')
      at belongsToNodeModules (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/transform/compilationCache.js:218:6)
      at shouldTransform (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/transform/transform.js:135:2)
      at resolveHook (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/transform/transform.js:83:7)
      at resolveFilename (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/transform/transform.js:189:23)
      at overridableRequire (:1:20)
      at folderIsModule (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/util.js:276:9)
      at fileIsModule (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/util.js:270:9)
      at /Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/transform/transform.js:168:8
      at requireOrImport (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/transform/transform.js:166:31)
      at /Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/common/configLoader.js:121:15
      at requireOrImportDefaultObject (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/common/configLoader.js:120:44)
      at /Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/common/configLoader.js:94:25
      at loadConfigFile (/Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/common/configLoader.js:92:23)
      at /Users/maximebrazeilles/workspaces/altavia-cloud/client/node_modules/playwright/lib/cli.js:118:41
      at processTicksAndRejections (:55:76)

Same for bun 1.0.6

@sacsbrainz
Copy link
Contributor

command bun run --watch src/index.ts

code:

const browser = await firefox.launch();
const context = await browser.newContext();
const page = await context.newPage();

Error:

launch: launch: undefined is not an object (evaluating 'pipeRead.on')
=========================== logs ===========================
<launching> /home/sacs/.cache/ms-playwright/firefox-1425/firefox/firefox -no-remote -headless -profile /tmp/playwright_firefoxdev_profile-qupyWf -juggler-pipe -silent
<launched> pid=40521
[pid=40521][err] *** You are running in headless mode.
[pid=40521][out] console.warn: services.settings: Ignoring preference override of remote settings server
[pid=40521][out] console.warn: services.settings: Allow by setting MOZ_REMOTE_SETTINGS_DEVTOOLS=1 in the environment
[pid=40521][out] Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: Unable to open a connection to the X server (t=0.241176) [GFX1-]: glxtest: Unable to open a connection to the X server
[pid=40521][out] console.error: ({})
[pid=40521][out] 
[pid=40521][out] Juggler listening to the pipe
============================================================

same for bun 1.0.9

@LevanKvirkvelia
Copy link

connecting to an existing browser does not work too.

@Jeanette3414
Copy link

Jeanette3414 commented Nov 30, 2023

Has anyone tried including the "useWebSocket": true field in LaunchOptions (it's not in the type declaration but the internal code uses it)? It seems to not immediately crash like in OP's stack trace, but it also seems to never resolve.. Maybe a temporary workaround could be made where playwright uses websockets instead of pipes to connect to the browser.

@LevanKvirkvelia
Copy link

LevanKvirkvelia commented Dec 20, 2023

checked with 1.0.18, still does not work :(

@meepeek
Copy link

meepeek commented Dec 31, 2023

1.0.20 also does not work. TypeError: undefined is not an object (evaluating 'pipeRead.on')

@luukvhoudt
Copy link

With a minimal reproduction I also get an undefined error with bun 1.0.21.

Minimal reproduction

  1. Install playwright.
bunx playwright install
bunx playwright install-deps
  1. Initialize a playwright project.
mkdir running-playwright-via-bun
bun init playwright@latest
  1. Create a test.
// File name: example.spec.ts

import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
  await page.goto('https://playwright.dev/');

  // Expect a title "to contain" a substring.
  await expect(page).toHaveTitle(/Playwright/);
});
  1. Run the test with playwright via bun.
bunx playwright test
# or
bunx playwright test example.spec.ts

TypeError: undefined is not an object (evaluating 'file.includes')

Error: No tests found

@Jarred-Sumner
Copy link
Collaborator

In the next version of Bun, Playwright seems to work, thanks to @nektro in #7958.

image

Related PR: microsoft/playwright#28875

@Prains
Copy link

Prains commented Jan 9, 2024

same problem.

bun 1.0.21

code:

import playwright from "playwright";


const browser = await playwright.chromium.launch({
  headless: false,
});

const page = await browser.newPage();

await page.goto("https://google.com");

input: bun index.ts

output:

bun index.ts
1 | import playwright from "playwright";
2 | 
                                                    ^
TypeError: launch: launch: undefined is not an object (evaluating 'pipeRead.on')
Call log:
  - <launching> /home/prains/.cache/ms-playwright/chromium-1091/chrome-linux/chrome --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,HttpsUpgrades --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-jUdWD4 --remote-debugging-pipe --no-startup-window
  - <launched> pid=3207

      at module code (/home/prains/b/index.ts:2:49)

@iRyusa
Copy link

iRyusa commented Jan 9, 2024

PR isn't yet merged so I don't think you'll be able to test it yet

@zoyspace
Copy link

zoyspace commented Jan 14, 2024

it work!!
bun --version
1.0.22

bun install playwright
bun index.ts

index.ts:

import { chromium } from 'playwright';

(async () => {
  const browser = await chromium.launch({ headless: false });
  const page = await browser.newPage();
  await page.goto('https://bun.sh/');
  await page.screenshot({ path: 'screen.png' });
  await browser.close();
})();

lgarron added a commit to cubing/cubing.js that referenced this issue Jan 14, 2024
Addresses a significant part of #294, thanks to oven-sh/bun#2492 .
@coopbri
Copy link

coopbri commented Jan 14, 2024

@zoyspace awesome!! Confirmed that running Playwright itself works with Bun runtime!

Tests (@playwright/test) don't seem to work though, not sure if there are workarounds yet

Modifying your snippet slightly:

import { chromium } from "playwright";
import { test } from "@playwright/test";

test("Bun website", async () => {
  const browser = await chromium.launch({ headless: false });
  const page = await browser.newPage();
  await page.goto("https://bun.sh/");
  await page.screenshot({ path: "screen.png" });
});

Result:

4 | test("Bun website", async () => {
    ^
TypeError: undefined is not a function (near '...test...')

@nektro
Copy link
Member

nektro commented Jan 14, 2024

that's dependent on microsoft/playwright#28935 (which is merged 😃) making it into the next playwright release

@nektro
Copy link
Member

nektro commented Jan 16, 2024

Playwright v1.41.0 which includes the above change has now been tagged and works together with Bun v1.0.22+.

$ bun create playwright@latest
$ bun x playwright test
image

@nemya9066
Copy link

yes can confirm that launching a browser now works in bun but the original problem mentioned here hasn't been solved.
The connectOverCDP method doesn't work in bun and the program just hangs.
I don't think this issue should be closed yet.

@iRyusa
Copy link

iRyusa commented Feb 16, 2024

Still not working on my side:

bun --bun x playwright test
TypeError: undefined is not an object (evaluating 'devices["Desktop Chrome"]')

Everything exported import { defineConfig, devices } from '@playwright/test' is just undefined.

bun --bun x playwright test still work fine tho, but I'm not convinced it use bun runtime as Bun is undefined

Edit: Test from Bun 1.0.22 to 1.0.26 & with latest 1.41.0/1.41.2 version of playwright

@iRyusa
Copy link

iRyusa commented Feb 16, 2024

It's so weird, using const { test, expect } = require('@playwright/test') does work fine, even if some tests freeze when there's multiple workers running test pass at some point.
No luck using import tho i'm having only undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
atw bug Something isn't working
Projects
None yet
Development

No branches or pull requests