Skip to content

Commit 9a9c51c

Browse files
committed
cherry-pick(#40733): chore(electron): revert #40184 (move Electron API to a separate package)
1 parent 4b3b628 commit 9a9c51c

49 files changed

Lines changed: 2804 additions & 1489 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/src/electron-api/class-electron.md

Lines changed: 62 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
* since: v1.9
33
* langs: js
44

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:
66

77
```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');
915

1016
(async () => {
1117
// Launch Electron app.
@@ -45,109 +51,6 @@ If you are not able to launch Electron and it will end up in timeouts during lau
4551

4652
* Ensure that `nodeCliInspect` ([FuseV1Options.EnableNodeCliInspectArguments](https://www.electronjs.org/docs/latest/tutorial/fuses#nodecliinspect)) fuse is **not** set to `false`.
4753

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-
15154
## async method: Electron.launch
15255
* since: v1.9
15356
- returns: <[ElectronApplication]>
@@ -186,5 +89,59 @@ Specifies environment variables that will be visible to Electron. Defaults to `p
18689

18790
Maximum time in milliseconds to wait for the application to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
18891

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+
189146
### option: Electron.launch.chromiumSandbox = %%-browser-option-chromiumsandbox-%%
190147
* since: v1.59

docs/src/electron-api/class-electronapplication.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ obtain the application instance. This instance you can control main electron pro
77
as well as work with Electron windows:
88

99
```js
10-
import { _electron as electron } from 'playwright';
10+
const { _electron: electron } = require('playwright');
1111

1212
(async () => {
1313
// Launch Electron app.

package-lock.json

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/isomorphic/protocolMetainfo.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,16 @@ export const methodMetainfo = new Map<string, MethodMetainfo>([
115115
['EventTarget.waitForEventInfo', { title: 'Wait for event "{info.event}"', snapshot: true, }],
116116
['AndroidDevice.waitForEventInfo', { title: 'Wait for event "{info.event}"', snapshot: true, }],
117117
['BrowserContext.waitForEventInfo', { title: 'Wait for event "{info.event}"', snapshot: true, }],
118+
['ElectronApplication.waitForEventInfo', { title: 'Wait for event "{info.event}"', snapshot: true, }],
118119
['WebSocket.waitForEventInfo', { title: 'Wait for event "{info.event}"', snapshot: true, }],
119120
['Page.waitForEventInfo', { title: 'Wait for event "{info.event}"', snapshot: true, }],
120121
['Debugger.waitForEventInfo', { title: 'Wait for event "{info.event}"', snapshot: true, }],
121122
['Worker.waitForEventInfo', { title: 'Wait for event "{info.event}"', snapshot: true, }],
123+
['Electron.launch', { title: 'Launch electron', }],
124+
['ElectronApplication.browserWindow', { internal: true, }],
125+
['ElectronApplication.evaluateExpression', { title: 'Evaluate', }],
126+
['ElectronApplication.evaluateExpressionHandle', { title: 'Evaluate', }],
127+
['ElectronApplication.updateSubscription', { internal: true, }],
122128
['Frame.evalOnSelector', { title: 'Evaluate', snapshot: true, pause: true, }],
123129
['Frame.evalOnSelectorAll', { title: 'Evaluate', snapshot: true, pause: true, }],
124130
['Frame.addScriptTag', { title: 'Add script tag', snapshot: true, pause: true, }],

0 commit comments

Comments
 (0)