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:
- electronApplication.on('close')
- electronApplication.on('window')
- electronApplication.close()
- electronApplication.context()
- electronApplication.evaluate(pageFunction[, arg])
- electronApplication.evaluateHandle(pageFunction, arg)
- electronApplication.firstWindow()
- electronApplication.waitForEvent(event[, optionsOrPredicate])
- electronApplication.windows()
#
electronApplication.on('close')This event is issued when the application closes.
#
electronApplication.on('window')- type: <Page>
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.
#
electronApplication.close()Closes Electron application.
#
electronApplication.context()- returns: <BrowserContext>
This method returns browser context that can be used for setting up context-wide routing, etc.
#
electronApplication.evaluate(pageFunction[, arg])pageFunction
<function|Electron> Function to be evaluated in the worker context.arg
<[EvaluationArgument]> Optional argument to pass topageFunction
.- returns: <Promise<Serializable>>
Returns the return value of pageFunction
.
If the function passed to the electronApplication.evaluate(pageFunction[, arg]) returns a Promise, then electronApplication.evaluate(pageFunction[, arg]) would wait for the promise to resolve and return its value.
If the function passed to the electronApplication.evaluate(pageFunction[, arg]) returns a non-Serializable value, then electronApplication.evaluate(pageFunction[, arg]) returns undefined
. Playwright also supports transferring some additional values that are not serializable by JSON
: -0
, NaN
, Infinity
, -Infinity
.
#
electronApplication.evaluateHandle(pageFunction, arg)pageFunction
<function|Electron> Function to be evaluated in the worker context.arg
<[EvaluationArgument]>- returns: <Promise<JSHandle>>
Returns the return value of pageFunction
as a JSHandle.
The only difference between electronApplication.evaluate(pageFunction[, arg]) and electronApplication.evaluateHandle(pageFunction, arg) is that electronApplication.evaluateHandle(pageFunction, arg) returns JSHandle.
If the function passed to the electronApplication.evaluateHandle(pageFunction, arg) returns a Promise, then electronApplication.evaluateHandle(pageFunction, arg) would wait for the promise to resolve and return its value.
#
electronApplication.firstWindow()Convenience method that waits for the first application window to be opened. Typically your script will start with:
#
electronApplication.waitForEvent(event[, optionsOrPredicate])event
<string> Event name, same one typically passed into*.on(event)
.optionsOrPredicate
<function|Object> Either a predicate that receives an event or an options object. Optional.predicate
<function> receives the event data and resolves to truthy value when the waiting should resolve.timeout
<number> maximum time to wait for in milliseconds. Defaults to30000
(30 seconds). Pass0
to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout).
- returns: <Promise<Object>>
Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value. Will throw an error if the application is closed before the event is fired. Returns the event data value.
#
electronApplication.windows()Convenience method that returns all the opened windows.