|
2 | 2 | * since: v1.9 |
3 | 3 | * langs: js |
4 | 4 |
|
5 | | -Playwright has **experimental** support for Electron automation, exposed as `_electron`. An example of the Electron automation script would be: |
| 5 | +Playwright has **experimental** support for Electron automation. You can access electron namespace via: |
6 | 6 |
|
7 | 7 | ```js |
8 | | -import { _electron as electron } from 'playwright'; |
| 8 | +const { _electron } = require('playwright'); |
| 9 | +``` |
| 10 | + |
| 11 | +An example of the Electron automation script would be: |
| 12 | + |
| 13 | +```js |
| 14 | +const { _electron: electron } = require('playwright'); |
9 | 15 |
|
10 | 16 | (async () => { |
11 | 17 | // Launch Electron app. |
@@ -45,109 +51,6 @@ If you are not able to launch Electron and it will end up in timeouts during lau |
45 | 51 |
|
46 | 52 | * Ensure that `nodeCliInspect` ([FuseV1Options.EnableNodeCliInspectArguments](https://www.electronjs.org/docs/latest/tutorial/fuses#nodecliinspect)) fuse is **not** set to `false`. |
47 | 53 |
|
48 | | -**Migrating from v1.59** |
49 | | - |
50 | | -A number of launch options have been removed after v1.59. See below for alternatives. |
51 | | - |
52 | | -* `recordHar` - use [`method: Tracing.startHar`]. |
53 | | - ```js |
54 | | - const electronApp = await electron.launch({ args: ['main.js'] }); |
55 | | - await electronApp.context().tracing.startHar('network.har'); |
56 | | - // ... drive the app ... |
57 | | - await electronApp.context().tracing.stopHar(); |
58 | | - await electronApp.close(); |
59 | | - ``` |
60 | | - |
61 | | -* `recordVideo` - use [`method: Screencast.start`] on each window. |
62 | | - ```js |
63 | | - const electronApp = await electron.launch({ args: ['main.js'] }); |
64 | | - const window = await electronApp.firstWindow(); |
65 | | - await window.screencast.start({ path: 'video.webm' }); |
66 | | - // ... drive the window ... |
67 | | - await window.screencast.stop(); |
68 | | - await electronApp.close(); |
69 | | - ``` |
70 | | - |
71 | | -* `colorScheme` - use [`method: Page.emulateMedia`] on each window. |
72 | | - ```js |
73 | | - const window = await electronApp.firstWindow(); |
74 | | - await window.emulateMedia({ colorScheme: 'dark' }); |
75 | | - ``` |
76 | | - |
77 | | -* `extraHTTPHeaders` - use [`method: BrowserContext.setExtraHTTPHeaders`]. |
78 | | - ```js |
79 | | - await electronApp.context().setExtraHTTPHeaders({ 'X-My-Header': 'value' }); |
80 | | - ``` |
81 | | - |
82 | | -* `geolocation` - use [`method: BrowserContext.setGeolocation`]. |
83 | | - ```js |
84 | | - await electronApp.context().setGeolocation({ latitude: 48.858455, longitude: 2.294474 }); |
85 | | - ``` |
86 | | - |
87 | | -* `httpCredentials` - use [`method: BrowserContext.setHTTPCredentials`]. |
88 | | - ```js |
89 | | - await electronApp.context().setHTTPCredentials({ username: 'user', password: 'pass' }); |
90 | | - ``` |
91 | | - |
92 | | -* `offline` - use [`method: BrowserContext.setOffline`]. |
93 | | - ```js |
94 | | - await electronApp.context().setOffline(true); |
95 | | - ``` |
96 | | - |
97 | | -* `bypassCSP` - disable CSP at the `BrowserWindow` level via Electron's [web preferences](https://www.electronjs.org/docs/latest/api/structures/web-preferences). Note that `webSecurity: false` also disables CORS and the Same-Origin Policy. |
98 | | - |
99 | | - ```js |
100 | | - const win = new BrowserWindow({ |
101 | | - webPreferences: { |
102 | | - webSecurity: false, |
103 | | - }, |
104 | | - }); |
105 | | - ``` |
106 | | - |
107 | | -* `ignoreHTTPSErrors` |
108 | | - |
109 | | - There are several ways to relax HTTPS checks in Electron. Pick the one that matches the scope you need. |
110 | | - |
111 | | - Per-window, allow mixed content through [web preferences](https://www.electronjs.org/docs/latest/api/structures/web-preferences): |
112 | | - |
113 | | - ```js |
114 | | - const win = new BrowserWindow({ |
115 | | - webPreferences: { |
116 | | - allowRunningInsecureContent: true, |
117 | | - }, |
118 | | - }); |
119 | | - ``` |
120 | | - |
121 | | - Process-wide, ignore certificate errors via Chromium command-line switches |
122 | | - (must run before the `ready` event): |
123 | | - |
124 | | - ```js |
125 | | - const { app } = require('electron'); |
126 | | - app.commandLine.appendSwitch('ignore-certificate-errors'); |
127 | | - // Optional: also ignore localhost certificate errors when testing on an IP. |
128 | | - app.commandLine.appendSwitch('allow-insecure-localhost', 'true'); |
129 | | - ``` |
130 | | - |
131 | | - Per-request, accept the certificate manually via the |
132 | | - [`certificate-error`](https://www.electronjs.org/docs/latest/api/app#event-certificate-error) |
133 | | - event: |
134 | | - |
135 | | - ```js |
136 | | - app.on('certificate-error', (event, webContents, url, error, certificate, callback) => { |
137 | | - event.preventDefault(); |
138 | | - callback(true); |
139 | | - }); |
140 | | - ``` |
141 | | - |
142 | | -* `timezoneId` - set an environment variable at the very top of the main file, before any other logic or Chromium windows are initialized. |
143 | | - ```js |
144 | | - // main.js |
145 | | - process.env.TZ = 'Europe/London'; |
146 | | - |
147 | | - const { app } = require('electron'); |
148 | | - // ... rest of your app logic |
149 | | - ``` |
150 | | - |
151 | 54 | ## async method: Electron.launch |
152 | 55 | * since: v1.9 |
153 | 56 | - returns: <[ElectronApplication]> |
@@ -186,5 +89,59 @@ Specifies environment variables that will be visible to Electron. Defaults to `p |
186 | 89 |
|
187 | 90 | Maximum time in milliseconds to wait for the application to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. |
188 | 91 |
|
| 92 | +### option: Electron.launch.acceptdownloads = %%-context-option-acceptdownloads-%% |
| 93 | +* since: v1.12 |
| 94 | + |
| 95 | +### option: Electron.launch.bypassCSP = %%-context-option-bypasscsp-%% |
| 96 | +* since: v1.12 |
| 97 | + |
| 98 | +### option: Electron.launch.colorScheme = %%-context-option-colorscheme-%% |
| 99 | +* since: v1.12 |
| 100 | + |
| 101 | +### option: Electron.launch.extraHTTPHeaders = %%-context-option-extrahttpheaders-%% |
| 102 | +* since: v1.12 |
| 103 | + |
| 104 | +### option: Electron.launch.geolocation = %%-context-option-geolocation-%% |
| 105 | +* since: v1.12 |
| 106 | + |
| 107 | +### option: Electron.launch.httpcredentials = %%-context-option-httpcredentials-%% |
| 108 | +* since: v1.12 |
| 109 | + |
| 110 | +### option: Electron.launch.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%% |
| 111 | +* since: v1.12 |
| 112 | + |
| 113 | +### option: Electron.launch.locale = %%-context-option-locale-%% |
| 114 | +* since: v1.12 |
| 115 | + |
| 116 | +### option: Electron.launch.offline = %%-context-option-offline-%% |
| 117 | +* since: v1.12 |
| 118 | + |
| 119 | +### option: Electron.launch.recordhar = %%-context-option-recordhar-%% |
| 120 | +* since: v1.12 |
| 121 | + |
| 122 | +### option: Electron.launch.recordharpath = %%-context-option-recordhar-path-%% |
| 123 | +* since: v1.12 |
| 124 | + |
| 125 | +### option: Electron.launch.recordHarOmitContent = %%-context-option-recordhar-omit-content-%% |
| 126 | +* since: v1.12 |
| 127 | + |
| 128 | +### option: Electron.launch.recordvideo = %%-context-option-recordvideo-%% |
| 129 | +* since: v1.12 |
| 130 | + |
| 131 | +### option: Electron.launch.recordvideodir = %%-context-option-recordvideo-dir-%% |
| 132 | +* since: v1.12 |
| 133 | + |
| 134 | +### option: Electron.launch.recordvideosize = %%-context-option-recordvideo-size-%% |
| 135 | +* since: v1.12 |
| 136 | + |
| 137 | +### option: Electron.launch.timezoneId = %%-context-option-timezoneid-%% |
| 138 | +* since: v1.12 |
| 139 | + |
| 140 | +### option: Electron.launch.tracesDir = %%-browser-option-tracesdir-%% |
| 141 | +* since: v1.36 |
| 142 | + |
| 143 | +### option: Electron.launch.artifactsDir = %%-browser-option-artifactsdir-%% |
| 144 | +* since: v1.59 |
| 145 | + |
189 | 146 | ### option: Electron.launch.chromiumSandbox = %%-browser-option-chromiumsandbox-%% |
190 | 147 | * since: v1.59 |
0 commit comments