Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions docs/src/api/class-browsertype.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,38 +236,6 @@ existing browser state. New contexts created via
are not affected. Defaults to `false`.


## async method: BrowserType.connectToWorker
* since: v1.60
* langs: js
- returns: <[Worker]>

This method attaches Playwright to an existing JavaScript engine exposing Chrome DevTools Protocol, for example to a Node.js process or an Electron application.

:::note
This is only supported on `chromium`.
:::

**Usage**

```js
const worker = await playwright.chromium.connectToWorker('http://localhost:9229');
const global = await worker.evaluate(() => globalThis);
```

### param: BrowserType.connectToWorker.endpoint
* since: v1.60
- `endpoint` <[string]>

A CDP websocket endpoint or http url to connect to. For example `http://localhost:9229/` or `ws://127.0.0.1:9229/something`.

### option: BrowserType.connectToWorker.timeout
* since: v1.60
- `timeout` <[float]>

Maximum time in milliseconds to wait for the connection to be established. Defaults to
`30000` (30 seconds). Pass `0` to disable timeout.


## method: BrowserType.executablePath
* since: v1.8
- returns: <[string]>
Expand Down
13 changes: 0 additions & 13 deletions docs/src/api/class-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,6 @@ Emitted when this dedicated [WebWorker](https://developer.mozilla.org/en-US/docs

Emitted when JavaScript within the worker calls one of console API methods, e.g. `console.log` or `console.dir`.

## async method: Worker.disconnect
* since: v1.60
* langs: js

Disconnects from a worker that was connected through [`method: BrowserType.connectToWorker`]. Calling this method on any other worker will throw.

### option: Worker.disconnect.reason
* since: v1.60
- `reason` <[string]>

The reason to be reported to the operations interrupted by the worker disconnect.


## async method: Worker.evaluate
* since: v1.8
- returns: <[Serializable]>
Expand Down
132 changes: 106 additions & 26 deletions docs/src/electron-api/class-electron.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,10 @@
* since: v1.9
* langs: js

Playwright supports Electron automation, shipped as a separate package.
Playwright has **experimental** support for Electron automation, exposed as `_electron`. An example of the Electron automation script would be:

```sh
npm i -D @playwright/electron
```

After installation, you can write a test or an automation script.

```js tab=js-test
import { test, expect } from '@playwright/electron';

test.use({ appOptions: { args: ['main.js'] } });

test('basic test', async ({ app, page }) => {
// Evaluate in the main Electron process.
const appPath = await app.evaluate(async ({ app }) => app.getAppPath());
console.log(appPath);

// Interact with the first window via the `page` fixture.
await expect(page).toHaveTitle(/My App/);
await page.click('text=Click me');
await expect(page.getByRole('heading')).toHaveText('Hello');
});
```

```js tab=js-library
import { electron } from '@playwright/electron';
```js
import { _electron as electron } from 'playwright';

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

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

**Migrating from v1.59**

A number of launch options have been removed after v1.59. See below for alternatives.

* `recordHar` - use [`method: Tracing.startHar`].
```js
const electronApp = await electron.launch({ args: ['main.js'] });
await electronApp.context().tracing.startHar('network.har');
// ... drive the app ...
await electronApp.context().tracing.stopHar();
await electronApp.close();
```

* `recordVideo` - use [`method: Screencast.start`] on each window.
```js
const electronApp = await electron.launch({ args: ['main.js'] });
const window = await electronApp.firstWindow();
await window.screencast.start({ path: 'video.webm' });
// ... drive the window ...
await window.screencast.stop();
await electronApp.close();
```

* `colorScheme` - use [`method: Page.emulateMedia`] on each window.
```js
const window = await electronApp.firstWindow();
await window.emulateMedia({ colorScheme: 'dark' });
```

* `extraHTTPHeaders` - use [`method: BrowserContext.setExtraHTTPHeaders`].
```js
await electronApp.context().setExtraHTTPHeaders({ 'X-My-Header': 'value' });
```

* `geolocation` - use [`method: BrowserContext.setGeolocation`].
```js
await electronApp.context().setGeolocation({ latitude: 48.858455, longitude: 2.294474 });
```

* `httpCredentials` - use [`method: BrowserContext.setHTTPCredentials`].
```js
await electronApp.context().setHTTPCredentials({ username: 'user', password: 'pass' });
```

* `offline` - use [`method: BrowserContext.setOffline`].
```js
await electronApp.context().setOffline(true);
```

* `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.

```js
const win = new BrowserWindow({
webPreferences: {
webSecurity: false,
},
});
```

* `ignoreHTTPSErrors`

There are several ways to relax HTTPS checks in Electron. Pick the one that matches the scope you need.

Per-window, allow mixed content through [web preferences](https://www.electronjs.org/docs/latest/api/structures/web-preferences):

```js
const win = new BrowserWindow({
webPreferences: {
allowRunningInsecureContent: true,
},
});
```

Process-wide, ignore certificate errors via Chromium command-line switches
(must run before the `ready` event):

```js
const { app } = require('electron');
app.commandLine.appendSwitch('ignore-certificate-errors');
// Optional: also ignore localhost certificate errors when testing on an IP.
app.commandLine.appendSwitch('allow-insecure-localhost', 'true');
```

Per-request, accept the certificate manually via the
[`certificate-error`](https://www.electronjs.org/docs/latest/api/app#event-certificate-error)
event:

```js
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
event.preventDefault();
callback(true);
});
```

* `timezoneId` - set an environment variable at the very top of the main file, before any other logic or Chromium windows are initialized.
```js
// main.js
process.env.TZ = 'Europe/London';

const { app } = require('electron');
// ... rest of your app logic
```

## async method: Electron.launch
* since: v1.9
- returns: <[ElectronApplication]>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/electron-api/class-electronapplication.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ obtain the application instance. This instance you can control main electron pro
as well as work with Electron windows:

```js
const { _electron: electron } = require('playwright');
import { _electron as electron } from 'playwright';

(async () => {
// Launch Electron app.
Expand Down
Loading
Loading