effect-playwright
    Preparing search index...

    Interface ElectronApplication

    Electron application representation. You can use electron.launch([options]) to obtain the application instance. This instance you can control main electron process as well as work with Electron windows:

    const { _electron: electron } = require('playwright');

    (async () => {
    // Launch Electron app.
    const electronApp = await electron.launch({ args: ['main.js'] });

    // Evaluation expression in the Electron context.
    const appPath = await electronApp.evaluate(async ({ app }) => {
    // This runs in the main Electron process, parameter here is always
    // the result of the require('electron') in the main app script.
    return app.getAppPath();
    });
    console.log(appPath);

    // Get the first window that the app opens, wait if necessary.
    const window = await electronApp.firstWindow();
    // Print the title.
    console.log(await window.title());
    // Capture a screenshot.
    await window.screenshot({ path: 'intro.png' });
    // Direct Electron console to Node terminal.
    window.on('console', console.log);
    // Click button.
    await window.click('text=Click me');
    // Exit app.
    await electronApp.close();
    })();
    interface ElectronApplication {
        "[asyncDispose]"(): Promise<void>;
        addListener(event: "close", listener: () => any): this;
        addListener(
            event: "console",
            listener: (consoleMessage: ConsoleMessage) => any,
        ): this;
        addListener(event: "window", listener: (page: Page) => any): this;
        browserWindow(page: Page): Promise<JSHandle<any>>;
        close(): Promise<void>;
        context(): BrowserContext;
        evaluate<R, Arg>(
            pageFunction: PageFunctionOn<any, Arg, R>,
            arg: Arg,
        ): Promise<R>;
        evaluate<R>(
            pageFunction: PageFunctionOn<any, void, R>,
            arg?: any,
        ): Promise<R>;
        evaluateHandle<R, Arg>(
            pageFunction: PageFunctionOn<any, Arg, R>,
            arg: Arg,
        ): Promise<SmartHandle<R>>;
        evaluateHandle<R>(
            pageFunction: PageFunctionOn<any, void, R>,
            arg?: any,
        ): Promise<SmartHandle<R>>;
        firstWindow(options?: { timeout?: number }): Promise<Page>;
        off(event: "close", listener: () => any): this;
        off(
            event: "console",
            listener: (consoleMessage: ConsoleMessage) => any,
        ): this;
        off(event: "window", listener: (page: Page) => any): this;
        on(event: "close", listener: () => any): this;
        on(
            event: "console",
            listener: (consoleMessage: ConsoleMessage) => any,
        ): this;
        on(event: "window", listener: (page: Page) => any): this;
        once(event: "close", listener: () => any): this;
        once(
            event: "console",
            listener: (consoleMessage: ConsoleMessage) => any,
        ): this;
        once(event: "window", listener: (page: Page) => any): this;
        prependListener(event: "close", listener: () => any): this;
        prependListener(
            event: "console",
            listener: (consoleMessage: ConsoleMessage) => any,
        ): this;
        prependListener(event: "window", listener: (page: Page) => any): this;
        process(): ChildProcess;
        removeListener(event: "close", listener: () => any): this;
        removeListener(
            event: "console",
            listener: (consoleMessage: ConsoleMessage) => any,
        ): this;
        removeListener(event: "window", listener: (page: Page) => any): this;
        waitForEvent(
            event: "close",
            optionsOrPredicate?:
                | {
                    predicate?: () => boolean | Promise<boolean>;
                    signal?: AbortSignal;
                    timeout?: number;
                }
                | (() => boolean | Promise<boolean>),
        ): Promise<void>;
        waitForEvent(
            event: "console",
            optionsOrPredicate?:
                | {
                    predicate?: (
                        consoleMessage: ConsoleMessage,
                    ) => boolean | Promise<boolean>;
                    signal?: AbortSignal;
                    timeout?: number;
                }
                | ((consoleMessage: ConsoleMessage) => boolean | Promise<boolean>),
        ): Promise<ConsoleMessage>;
        waitForEvent(
            event: "window",
            optionsOrPredicate?:
                | {
                    predicate?: (page: Page) => boolean | Promise<boolean>;
                    signal?: AbortSignal;
                    timeout?: number;
                }
                | ((page: Page) => boolean | Promise<boolean>),
        ): Promise<Page>;
        windows(): Page[];
    }
    Index
    • Returns Promise<void>

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

      Parameters

      • event: "close"
      • listener: () => any

      Returns this

    • Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. console.log or console.dir.

      The arguments passed into console.log are available on the ConsoleMessage event handler argument.

      Usage

      electronApp.on('console', async msg => {
      const values = [];
      for (const arg of msg.args())
      values.push(await arg.jsonValue());
      console.log(...values);
      });
      await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));

      Parameters

      Returns this

    • This event is issued for every window that is created and loaded in Electron. It contains a Page that can be used for Playwright automation.

      Parameters

      • event: "window"
      • listener: (page: Page) => any

      Returns this

    • Returns the BrowserWindow object that corresponds to the given Playwright page.

      Parameters

      • page: Page

        Page to retrieve the window for.

      Returns Promise<JSHandle<any>>

    • Closes Electron application.

      Returns Promise<void>

    • This method returns browser context that can be used for setting up context-wide routing, etc.

      Returns BrowserContext

    • Convenience method that waits for the first application window to be opened.

      Usage

      const electronApp = await electron.launch({
      args: ['main.js']
      });
      const window = await electronApp.firstWindow();
      // ...

      Parameters

      • Optionaloptions: { timeout?: number }
        • Optionaltimeout?: number

          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).

      Returns Promise<Page>

    • Removes an event listener added by on or addListener.

      Parameters

      • event: "close"
      • listener: () => any

      Returns this

    • Removes an event listener added by on or addListener.

      Parameters

      Returns this

    • Removes an event listener added by on or addListener.

      Parameters

      • event: "window"
      • listener: (page: Page) => any

      Returns this

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

      Parameters

      • event: "close"
      • listener: () => any

      Returns this

    • Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. console.log or console.dir.

      The arguments passed into console.log are available on the ConsoleMessage event handler argument.

      Usage

      electronApp.on('console', async msg => {
      const values = [];
      for (const arg of msg.args())
      values.push(await arg.jsonValue());
      console.log(...values);
      });
      await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));

      Parameters

      Returns this

    • This event is issued for every window that is created and loaded in Electron. It contains a Page that can be used for Playwright automation.

      Parameters

      • event: "window"
      • listener: (page: Page) => any

      Returns this

    • Adds an event listener that will be automatically removed after it is triggered once. See addListener for more information about this event.

      Parameters

      • event: "close"
      • listener: () => any

      Returns this

    • Adds an event listener that will be automatically removed after it is triggered once. See addListener for more information about this event.

      Parameters

      Returns this

    • Adds an event listener that will be automatically removed after it is triggered once. See addListener for more information about this event.

      Parameters

      • event: "window"
      • listener: (page: Page) => any

      Returns this

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

      Parameters

      • event: "close"
      • listener: () => any

      Returns this

    • Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. console.log or console.dir.

      The arguments passed into console.log are available on the ConsoleMessage event handler argument.

      Usage

      electronApp.on('console', async msg => {
      const values = [];
      for (const arg of msg.args())
      values.push(await arg.jsonValue());
      console.log(...values);
      });
      await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));

      Parameters

      Returns this

    • This event is issued for every window that is created and loaded in Electron. It contains a Page that can be used for Playwright automation.

      Parameters

      • event: "window"
      • listener: (page: Page) => any

      Returns this

    • Returns the main process for this Electron Application.

      Returns ChildProcess

    • Removes an event listener added by on or addListener.

      Parameters

      • event: "close"
      • listener: () => any

      Returns this

    • Removes an event listener added by on or addListener.

      Parameters

      Returns this

    • Removes an event listener added by on or addListener.

      Parameters

      • event: "window"
      • listener: (page: Page) => any

      Returns this

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

      Parameters

      • event: "close"
      • OptionaloptionsOrPredicate:
            | {
                predicate?: () => boolean | Promise<boolean>;
                signal?: AbortSignal;
                timeout?: number;
            }
            | (() => boolean | Promise<boolean>)

      Returns Promise<void>

    • Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. console.log or console.dir.

      The arguments passed into console.log are available on the ConsoleMessage event handler argument.

      Usage

      electronApp.on('console', async msg => {
      const values = [];
      for (const arg of msg.args())
      values.push(await arg.jsonValue());
      console.log(...values);
      });
      await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));

      Parameters

      • event: "console"
      • OptionaloptionsOrPredicate:
            | {
                predicate?: (
                    consoleMessage: ConsoleMessage,
                ) => boolean | Promise<boolean>;
                signal?: AbortSignal;
                timeout?: number;
            }
            | ((consoleMessage: ConsoleMessage) => boolean | Promise<boolean>)

      Returns Promise<ConsoleMessage>

    • This event is issued for every window that is created and loaded in Electron. It contains a Page that can be used for Playwright automation.

      Parameters

      • event: "window"
      • OptionaloptionsOrPredicate:
            | {
                predicate?: (page: Page) => boolean | Promise<boolean>;
                signal?: AbortSignal;
                timeout?: number;
            }
            | ((page: Page) => boolean | Promise<boolean>)

      Returns Promise<Page>

    • Convenience method that returns all the opened windows.

      Returns Page[]