Skip to content
Closed
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
39 changes: 39 additions & 0 deletions docs/src/electron-api/class-electronapplication.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,45 @@ const { _electron: electron } = require('playwright');

This event is issued when the application process has been terminated.

## event: ElectronApplication.dialog
* since: v1.61
- argument: <[ElectronDialog]>

Emitted when the Electron main process invokes a message dialog method —
`dialog.showMessageBox` or `dialog.showCertificateTrustDialog`. The handler is expected to
either [`method: ElectronDialog.accept`] with the desired result or
[`method: ElectronDialog.dismiss`] the dialog. If no handler is attached, the original
Electron dialog methods are called as usual.

For file selection dialogs (`showOpenDialog`/`showSaveDialog`) see
[`event: ElectronApplication.fileChooser`].

**Usage**

```js
electronApp.on('dialog', async dialog => {
await dialog.accept({ response: 0, checkboxChecked: false });
});
```

## event: ElectronApplication.fileChooser
* since: v1.61
- argument: <[ElectronFileChooser]>

Emitted when the Electron main process invokes a file dialog method —
`dialog.showOpenDialog` or `dialog.showSaveDialog`. The handler is expected to either
[`method: ElectronFileChooser.setFiles`] to fulfill the dialog with file paths or
[`method: ElectronFileChooser.cancel`] to cancel it. If no handler is attached, the
original Electron dialog methods are called as usual.

**Usage**

```js
electronApp.on('fileChooser', async chooser => {
await chooser.setFiles(['/path/to/file.txt']);
});
```

## event: ElectronApplication.console
* since: v1.42
- argument: <[ConsoleMessage]>
Expand Down
47 changes: 47 additions & 0 deletions docs/src/electron-api/class-electrondialog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# class: ElectronDialog
* since: v1.61
* langs: js

Represents a message dialog initiated by the Electron main process via [`dialog.showMessageBox`](https://www.electronjs.org/docs/latest/api/dialog#dialogshowmessageboxbrowserwindow-options)
or [`dialog.showCertificateTrustDialog`](https://www.electronjs.org/docs/latest/api/dialog#dialogshowcertificatetrustdialogbrowserwindow-options-macos-windows).

Instances of this class are received via the [`event: ElectronApplication.dialog`] event.
For file selection dialogs (`showOpenDialog`/`showSaveDialog`) see [ElectronFileChooser].

```js
electronApp.on('dialog', async dialog => {
// dialog.method() === 'showMessageBox' | 'showCertificateTrustDialog'
await dialog.accept({ response: 1, checkboxChecked: false });
});
```

## async method: ElectronDialog.accept
* since: v1.61

Resolves the underlying Electron dialog with the provided result. For `showMessageBox` the
expected shape is `{ response: number, checkboxChecked?: boolean }`.

### param: ElectronDialog.accept.result
* since: v1.61
- `result` <[Serializable]>

The value to resolve the dialog with.

## async method: ElectronDialog.dismiss
* since: v1.61

Dismisses the dialog. The Electron dialog method resolves with a default value — for
`showMessageBox` that is `{ response: 0, checkboxChecked: false }`.

## method: ElectronDialog.method
* since: v1.61
- returns: <[string]<"showMessageBox"|"showCertificateTrustDialog">>

The name of the [Electron dialog method](https://www.electronjs.org/docs/latest/api/dialog) that triggered the
event.

## method: ElectronDialog.options
* since: v1.61
- returns: <[Serializable]>

The options object that was passed to the underlying Electron dialog method.
51 changes: 51 additions & 0 deletions docs/src/electron-api/class-electronfilechooser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# class: ElectronFileChooser
* since: v1.61
* langs: js

Represents a file selection dialog initiated by the Electron main process via
[`dialog.showOpenDialog`](https://www.electronjs.org/docs/latest/api/dialog#dialogshowopendialogbrowserwindow-options)
or [`dialog.showSaveDialog`](https://www.electronjs.org/docs/latest/api/dialog#dialogshowsavedialogbrowserwindow-options).

Instances of this class are received via the [`event: ElectronApplication.fileChooser`] event.
Tests can call [`method: ElectronFileChooser.setFiles`] to fulfill the dialog with the given
file paths, or [`method: ElectronFileChooser.cancel`] to cancel the dialog.

```js
electronApp.on('fileChooser', async chooser => {
await chooser.setFiles(['/path/to/file.txt']);
});
```

## async method: ElectronFileChooser.setFiles
* since: v1.61

Resolves the underlying Electron file dialog with the provided paths.

For [`dialog.showOpenDialog`] the dialog resolves with
`{ canceled: false, filePaths: [...] }`. For [`dialog.showSaveDialog`] the dialog resolves
with `{ canceled: false, filePath: filePaths[0] }`.

### param: ElectronFileChooser.setFiles.filePaths
* since: v1.61
- `filePaths` <[string]|[Array]<[string]>>

The file path(s) to provide to the Electron dialog.

## async method: ElectronFileChooser.cancel
* since: v1.61

Cancels the file dialog. The Electron dialog method resolves with `{ canceled: true, filePaths: [] }`
for `showOpenDialog`, or `{ canceled: true, filePath: '' }` for `showSaveDialog`.

## method: ElectronFileChooser.method
* since: v1.61
- returns: <[string]<"showOpenDialog"|"showSaveDialog">>

The name of the [Electron dialog method](https://www.electronjs.org/docs/latest/api/dialog) that triggered the
event.

## method: ElectronFileChooser.options
* since: v1.61
- returns: <[Serializable]>

The options object that was passed to the underlying Electron dialog method.
4 changes: 4 additions & 0 deletions packages/isomorphic/protocolMetainfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ export const methodMetainfo = new Map<string, MethodMetainfo>([
['ElectronApplication.evaluateExpression', { title: 'Evaluate', }],
['ElectronApplication.evaluateExpressionHandle', { title: 'Evaluate', }],
['ElectronApplication.updateSubscription', { internal: true, }],
['ElectronDialog.accept', { title: 'Accept dialog', }],
['ElectronDialog.dismiss', { title: 'Dismiss dialog', }],
['ElectronFileChooser.setFiles', { title: 'Set files for the dialog', }],
['ElectronFileChooser.cancel', { title: 'Cancel the file chooser', }],
['Frame.evalOnSelector', { title: 'Evaluate', snapshot: true, pause: true, }],
['Frame.evalOnSelectorAll', { title: 'Evaluate', snapshot: true, pause: true, }],
['Frame.addScriptTag', { title: 'Add script tag', snapshot: true, pause: true, }],
Expand Down
Loading
Loading