From 5223c1ba39114dec5b0baf9ec17800cea612f9ce Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Fri, 31 Mar 2023 22:35:54 +0000 Subject: [PATCH] feat: add timeout to `electron.firstWindow()` method (#21863) Fixes https://github.com/microsoft/playwright/issues/21846 --- docs/src/api/class-electronapplication.md | 8 ++++++++ packages/playwright-core/src/client/electron.ts | 4 ++-- packages/playwright-core/types/types.d.ts | 10 +++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/src/api/class-electronapplication.md b/docs/src/api/class-electronapplication.md index 6881bfee83..e848f4a6ab 100644 --- a/docs/src/api/class-electronapplication.md +++ b/docs/src/api/class-electronapplication.md @@ -135,6 +135,14 @@ Convenience method that waits for the first application window to be opened. // ... ``` +### option: ElectronApplication.firstWindow.timeout +* since: v1.33 +- `timeout` ?<[float]> + +Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). +Pass `0` to disable timeout. The default value can be changed by using the +[`method: BrowserContext.setDefaultTimeout`]. + ## method: ElectronApplication.process * since: v1.21 - returns: <[ChildProcess]> diff --git a/packages/playwright-core/src/client/electron.ts b/packages/playwright-core/src/client/electron.ts index dfdfbb8664..2a4d2d7f3e 100644 --- a/packages/playwright-core/src/client/electron.ts +++ b/packages/playwright-core/src/client/electron.ts @@ -95,10 +95,10 @@ export class ElectronApplication extends ChannelOwner { + async firstWindow(options?: { timeout?: number }): Promise { if (this._windows.size) return this._windows.values().next().value; - return this.waitForEvent('window'); + return this.waitForEvent('window', options); } context(): BrowserContext { diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts index 0594a9a1b6..99337e9769 100644 --- a/packages/playwright-core/types/types.d.ts +++ b/packages/playwright-core/types/types.d.ts @@ -13402,8 +13402,16 @@ export interface ElectronApplication { * // ... * ``` * + * @param options */ - firstWindow(): Promise; + firstWindow(options?: { + /** + * Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The + * default value can be changed by using the + * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browser-context-set-default-timeout). + */ + timeout?: number; + }): Promise; /** * Returns the main process for this Electron Application.