|
| 1 | +# Managing browser binaries |
| 2 | + |
| 3 | +Playwright comes bundled with browsers, and by default `npm i playwright` downloads |
| 4 | +all 3 browsers inside the `node_modules/` folder. This way no extra steps are needed |
| 5 | +to get playwright up and running. |
| 6 | + |
| 7 | +However, Playwright also has rich configuration to support various strategies |
| 8 | +for browser management. |
| 9 | + |
| 10 | +## Download from artifact repository |
| 11 | + |
| 12 | +By default, Playwright downloads browsers from Microsoft and Google public CDNs. |
| 13 | + |
| 14 | +Sometimes companies maintain an internal artifact repository to host browser |
| 15 | +binaries. In this case, Playwright can be configured to download from a custom |
| 16 | +location using the `PLAYWRIGHT_DOWNLOAD_HOST` env variable. |
| 17 | + |
| 18 | +```sh |
| 19 | +$ PLAYWRIGHT_DOWNLOAD_HOST=192.168.1.78 npm i playwright |
| 20 | +``` |
| 21 | + |
| 22 | +## Share browser binaries across projects |
| 23 | + |
| 24 | +Sometimes developers work with multiple NPM projects that all use Playwright. |
| 25 | +By default, every project will have browser binaries in its own `node_modules/` folder. |
| 26 | +To save some HDD space and to speedup installation, Playwright can re-use |
| 27 | +browser binaries. |
| 28 | + |
| 29 | +Sharing browser binaries is a two-step process: |
| 30 | + |
| 31 | +1. When installing Playwright, ask it to download browsers into a shared location: |
| 32 | + |
| 33 | +```sh |
| 34 | +$ PLAYWRIGHT_BROWSERS_PATH=$HOME/pw-browsers npm i playwright |
| 35 | +``` |
| 36 | + |
| 37 | +2. When running Playwright scripts, ask it to search for browsers in a shared location: |
| 38 | + |
| 39 | +```sh |
| 40 | +$ PLAYWRIGHT_BROWSERS_PATH=$HOME/pw-browsers node playwright-script.js |
| 41 | +``` |
| 42 | + |
| 43 | +> **NOTE** Developers can opt-in in this mode via exporting `PLAYWRIGHT_BROWSERS_PATH=$HOME/pw-browsers` in their `.bashrc`. |
| 44 | +
|
| 45 | +## Completely avoid browser installation |
| 46 | + |
| 47 | +In certain cases, it is desired to avoid browser installation altogether because |
| 48 | +browser binaries are managed separately. |
| 49 | + |
| 50 | +This can be done by setting `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` variable before installation. |
| 51 | + |
| 52 | +```sh |
| 53 | +$ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i playwright |
| 54 | +``` |
| 55 | + |
| 56 | +## Download single browser binary |
| 57 | + |
| 58 | +Playwright ships three packages that bundle only a single browser: |
| 59 | +- [`playwright-chromium`](https://www.npmjs.com/package/playwright-chromium) |
| 60 | +- [`playwright-webkit`](https://www.npmjs.com/package/playwright-webkit) |
| 61 | +- [`playwright-firefox`](https://www.npmjs.com/package/playwright-firefox) |
| 62 | + |
| 63 | +> **NOTE** All configuration environment variables also apply to these packages. |
| 64 | +
|
| 65 | +Using these packages is as easy as using a regular Playwright: |
| 66 | + |
| 67 | +1. Install a specific package |
| 68 | + |
| 69 | +```sh |
| 70 | +$ npm i playwright-webkit |
| 71 | +``` |
| 72 | + |
| 73 | +2. Requre package |
| 74 | + |
| 75 | +```js |
| 76 | +// Notice a proper package name in require |
| 77 | +const {webkit} = require('playwright-webkit'); |
| 78 | + |
| 79 | +(async () => { |
| 80 | + const browser = await webkit.launch(); |
| 81 | + // .... |
| 82 | +})(); |
| 83 | +``` |
0 commit comments