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

[Question] Access browser binaries from node_modules/playwright directory? #4808

Closed
nwittwer opened this issue Dec 22, 2020 · 3 comments
Closed

Comments

@nwittwer
Copy link

nwittwer commented Dec 22, 2020

Hi, I'm trying access the browser binaries (e.g. Firefox, WebKit), but am not seeing the expected files after running PLAYWRIGHT_BROWSERS_PATH=0 yarn add playwright and yarn install with the same. I expect to see a .browsers-local directory within ./node_modules/playwright/, as does the error message.

script.js (FYI: this runs within Electron)

process.env.PLAYWRIGHT_BROWSERS_PATH = 0 // set the environment variable in the app
const browser = await playwright['webkit'].launch();

Error logs

Uncaught (in promise) browserType.launch: Failed to launch webkit because executable doesn't exist at C:\Users\hi\Documents\MYPROJECT\node_modules\playwright\.local-browsers\webkit-1402\Playwright.exe
Try re-installing playwright with "npm install playwright"
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.
    at Connection.sendMessageToServer (C:\Users\hi\Documents\MYPROJECT\node_modules\playwright\lib\client\connection.js:69:15)
    at Proxy.<anonymous> (C:\Users\hi\Documents\MYPROJECT\node_modules\playwright\lib\client\channelOwner.js:44:61)
    at C:\Users\hi\Documents\MYPROJECT\node_modules\playwright\lib\client\browserType.js:61:73
    at BrowserType._wrapApiCall (C:\Users\hi\Documents\MYPROJECT\node_modules\playwright\lib\client\channelOwner.js:72:34)
    at BrowserType.launch (C:\Users\hi\Documents\MYPROJECT\node_modules\playwright\lib\client\browserType.js:52:21)
    at CrossBrowserScreenshot._callee$ (webpack-internal:///./src/renderer/components/CrossBrowser/Screenshots/index.js:118:89)
    at tryCatch (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:63:40)
    at Generator.invoke [as _invoke] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:293:22)
    at Generator.eval [as next] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:118:21)
    at asyncGeneratorStep (webpack-internal:///./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:5:24)

Uncaught (in promise) browserType.launch: Failed to launch firefox because executable doesn't exist at C:\Users\hi\Documents\MYPROJECT\node_modules\playwright\.local-browsers\firefox-1221\firefox\firefox.exe
Try re-installing playwright with "npm install playwright"
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.
    at Connection.sendMessageToServer (C:\Users\hi\Documents\MYPROJECT\node_modules\playwright\lib\client\connection.js:69:15)
    at Proxy.<anonymous> (C:\Users\hi\Documents\MYPROJECT\node_modules\playwright\lib\client\channelOwner.js:44:61)
    at C:\Users\hi\Documents\MYPROJECT\node_modules\playwright\lib\client\browserType.js:61:73
    at BrowserType._wrapApiCall (C:\Users\hi\Documents\MYPROJECT\node_modules\playwright\lib\client\channelOwner.js:72:34)
    at BrowserType.launch (C:\Users\hi\Documents\MYPROJECT\node_modules\playwright\lib\client\browserType.js:52:21)
    at CrossBrowserScreenshot._callee$ (webpack-internal:///./src/renderer/components/CrossBrowser/Screenshots/index.js:118:89)
    at tryCatch (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:63:40)
    at Generator.invoke [as _invoke] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:293:22)
    at Generator.eval [as next] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:118:21)
    at asyncGeneratorStep (webpack-internal:///./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:5:24)
  • OS: Windows 10
  • Node v41.15.3
  • Yarn v1.22.5
  • Playwright v1.7.1
  1. npx cross-env PLAYWRIGHT_BROWSERS_PATH=0 yarn add playwright -S
    • The PLAYWRIGHT_BROWSERS_PATH=0 environment variable is mentioned in the docs here
  2. I looked inside of node_modules/playwright, expecting to see a .browsers-local directory, but found nothing like that

Question
How can I reliably access the browser binaries directory? It seems like it should be as simple as installing the package and running the package using the env variable PLAYWRIGHT_BROWSERS_PATH=0, however I am not able to see the downloaded browser directories.

(My end goal is to be able to launch the browsers installed in .node_modules/playright from an Electron app. If PLAYWRIGHT_BROWSERS_PATH=0 still works as intended, that appears to be the easies way to achieve this.)


Similar issues I've looked at:

@nwittwer nwittwer changed the title [Question] Accessing browser binaries PLAYWRIGHT_BROWSERS_PATH [Question] Access browser binaries from node_modules/playwright directory? Dec 22, 2020
@yury-s
Copy link
Member

yury-s commented Dec 23, 2020

The directory name is .local-browsers not .browsers-local. If PLAYWRIGHT_BROWSERS_PATH=0 is set the installer should print where the browsers are downloaded (something like '/home/hi/example/node_modules/playwright/.local-browsers/webkit-1402'), if the directory is not there someone has deleted it.

In your code snippet

process.env.PLAYWRIGHT_BROWSERS_PATH = 0 

is done too late, by that time browser types would already be initialized with the default path. But looking at your traces it looks like you did pass the env variable differently. Can you post here complete snippet that doesn't work?

@nwittwer
Copy link
Author

Thanks @yury-s.

  1. In a fresh repository running npx cross-env PLAYWRIGHT_BROWSERS_PATH=0 yarn add playwright -S worked exactly as it should. Was able to do the same in my project succesfully. For some reason set PLAYWRIGHT_BROWSERS_PATH=0 was not working reliably on its own. I'm not as familiar with Windows as I am with MacOS, so perhaps its an issue with the PowerShell or my terminal in VSCode.

Logs while using set env

PS C:\Users\hi\Desktop\playwright-test> set PLAYWRIGHT_BROWSERS_PATH=0
PS C:\Users\hi\Desktop\playwright-test> yarn add playwright -S
yarn add v1.22.5
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 35 new dependencies.
info Direct dependencies
└─ playwright@1.7.1
info All dependencies
├─ @types/node@14.14.14
├─ @types/yauzl@2.9.1
├─ agent-base@6.0.2
├─ balanced-match@1.0.0
├─ brace-expansion@1.1.11
├─ buffer-crc32@0.2.13
├─ concat-map@0.0.1
├─ end-of-stream@1.4.4
├─ extract-zip@2.0.1
├─ fd-slicer@1.1.0
├─ fs.realpath@1.0.0
├─ get-stream@5.2.0
├─ glob@7.1.6
├─ graceful-fs@4.2.4
├─ https-proxy-agent@5.0.0
├─ inflight@1.0.6
├─ inherits@2.0.4
├─ jpeg-js@0.4.2
├─ mime@2.4.7
├─ minimatch@3.0.4
├─ ms@2.1.2
├─ once@1.4.0
├─ path-is-absolute@1.0.1
├─ pend@1.2.0
├─ playwright@1.7.1
├─ pngjs@5.0.0
├─ progress@2.0.3
├─ proper-lockfile@4.1.1
├─ proxy-from-env@1.1.0
├─ pump@3.0.0
├─ retry@0.12.0
├─ rimraf@3.0.2
├─ signal-exit@3.0.3
├─ ws@7.4.1
└─ yauzl@2.10.0
Done in 4.34s.

Logs when using npx cross-env PLAYWRIGHT_BROWSERS_PATH=0 yarn add playwright -S

PS C:\Users\hi\Desktop\playwright-test> npx cross-env PLAYWRIGHT_BROWSERS_PATH=0 yarn add playwright -S
npx: installed 7 in 1.991s
yarn add v1.22.5
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 35 new dependencies.
info Direct dependencies
└─ playwright@1.7.1
info All dependencies
├─ @types/node@14.14.14
├─ @types/yauzl@2.9.1
├─ agent-base@6.0.2
├─ balanced-match@1.0.0
├─ brace-expansion@1.1.11
├─ buffer-crc32@0.2.13
├─ concat-map@0.0.1
├─ end-of-stream@1.4.4
├─ extract-zip@2.0.1
├─ fd-slicer@1.1.0
├─ fs.realpath@1.0.0
├─ get-stream@5.2.0
├─ glob@7.1.6
├─ graceful-fs@4.2.4
├─ https-proxy-agent@5.0.0
├─ inflight@1.0.6
├─ inherits@2.0.4
├─ jpeg-js@0.4.2
├─ mime@2.4.7
├─ minimatch@3.0.4
├─ ms@2.1.2
├─ once@1.4.0
├─ path-is-absolute@1.0.1
├─ pend@1.2.0
├─ playwright@1.7.1
├─ pngjs@5.0.0
├─ progress@2.0.3
├─ proper-lockfile@4.1.1
├─ proxy-from-env@1.1.0
├─ pump@3.0.0
├─ retry@0.12.0
├─ rimraf@3.0.2
├─ signal-exit@3.0.3
├─ ws@7.4.1
└─ yauzl@2.10.0
Done in 242.33s.
  1. You were also correct about the process.env.PLAYWRIGHT_BROWSERS_PATH = 0 being set too late. I'm using Electron, so I moved this line out from a JS function in the web app itself (part of renderer) and into the main process. This appears to be working correctly.

main process (Node)

import { BrowserWindow, app } from 'electron'

process.env.PLAYWRIGHT_BROWSERS_PATH = 0 // <-- setting the environment variable inside the main (Node) process

const win = new BrowserWindow({ width: 800, height: 600 });
if (isDev) win.loadURL(DEV_SERVER_URL);
else win.loadFile(INDEX_PATH); // bundled web app

@dgozman
Copy link
Contributor

dgozman commented Dec 23, 2020

Closing since the issue seems resolved.

@dgozman dgozman closed this as completed Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants