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();
})();

Hierarchy

  • ElectronApplication

Methods

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

    Parameters

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

    Returns ElectronApplication

  • 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"
    • listener: ((consoleMessage) => any)
        • (consoleMessage): any
        • Parameters

          Returns any

    Returns ElectronApplication

  • 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) => any)
        • (page): any
        • Parameters

          Returns any

    Returns ElectronApplication

  • 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

    • Optional options: {
          timeout?: number;
      }
      Optional
      • Optional timeout?: 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)
        • (): any
        • Returns any

    Returns ElectronApplication

  • Removes an event listener added by on or addListener.

    Parameters

    • event: "console"
    • listener: ((consoleMessage) => any)
        • (consoleMessage): any
        • Parameters

          Returns any

    Returns ElectronApplication

  • Removes an event listener added by on or addListener.

    Parameters

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

          Returns any

    Returns ElectronApplication

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

    Parameters

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

    Returns ElectronApplication

  • 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"
    • listener: ((consoleMessage) => any)
        • (consoleMessage): any
        • Parameters

          Returns any

    Returns ElectronApplication

  • 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) => any)
        • (page): any
        • Parameters

          Returns any

    Returns ElectronApplication

  • 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)
        • (): any
        • Returns any

    Returns ElectronApplication

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

    Parameters

    • event: "console"
    • listener: ((consoleMessage) => any)
        • (consoleMessage): any
        • Parameters

          Returns any

    Returns ElectronApplication

  • 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) => any)
        • (page): any
        • Parameters

          Returns any

    Returns ElectronApplication

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

    Parameters

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

    Returns ElectronApplication

  • 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"
    • listener: ((consoleMessage) => any)
        • (consoleMessage): any
        • Parameters

          Returns any

    Returns ElectronApplication

  • 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) => any)
        • (page): any
        • Parameters

          Returns any

    Returns ElectronApplication

  • Returns the main process for this Electron Application.

    Returns ChildProcess

  • Removes an event listener added by on or addListener.

    Parameters

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

    Returns ElectronApplication

  • Removes an event listener added by on or addListener.

    Parameters

    • event: "console"
    • listener: ((consoleMessage) => any)
        • (consoleMessage): any
        • Parameters

          Returns any

    Returns ElectronApplication

  • Removes an event listener added by on or addListener.

    Parameters

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

          Returns any

    Returns ElectronApplication

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

    Parameters

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

    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"
    • Optional optionsOrPredicate: {
          predicate?: ((consoleMessage) => boolean | Promise<boolean>);
          timeout?: number;
      } | ((consoleMessage) => boolean | Promise<boolean>)
      Optional

    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"
    • Optional optionsOrPredicate: {
          predicate?: ((page) => boolean | Promise<boolean>);
          timeout?: number;
      } | ((page) => boolean | Promise<boolean>)
      Optional

    Returns Promise<Page>

  • Convenience method that returns all the opened windows.

    Returns Page[]

Generated using TypeDoc