1"use strict";(self.webpackChunkplaywright_dev=self.webpackChunkplaywright_dev||[]).push([["4604"],{15147(e,n,i){i.r(n),i.d(n,{metadata:()=>t,default:()=>p,frontMatter:()=>a,contentTitle:()=>r,toc:()=>c,assets:()=>o});var t=JSON.parse('{"id":"api/class-electronapplication","title":"ElectronApplication","description":"Electron application representation. You can use electron.launch() to obtain the application instance. This instance you can control main electron process as well as work with Electron windows:","source":"@site/docs/api/class-electronapplication.mdx","sourceDirName":"api","slug":"/api/class-electronapplication","permalink":"/docs/next/api/class-electronapplication","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"id":"class-electronapplication","title":"ElectronApplication"},"sidebar":"api","previous":{"title":"Electron","permalink":"/docs/next/api/class-electron"}}'),l=i(74848),s=i(28453);i(13554),i(41647),i(83137);let a={id:"class-electronapplication",title:"ElectronApplication"},r,o={},c=[{value:"Methods",id:"methods",level:2},{value:"browserWindow",id:"electron-application-browser-window",level:3},{value:"close",id:"electron-application-close",level:3},{value:"context",id:"electron-application-context",level:3},{value:"evaluate",id:"electron-application-evaluate",level:3},{value:"evaluateHandle",id:"electron-application-evaluate-handle",level:3},{value:"firstWindow",id:"electron-application-first-window",level:3},{value:"process",id:"electron-application-process",level:3},{value:"waitForEvent",id:"electron-application-wait-for-event",level:3},{value:"windows",id:"electron-application-windows",level:3},{value:"Events",id:"events",level:2},{value:"on('close')",id:"electron-application-event-close",level:3},{value:"on('console')",id:"electron-application-event-console",level:3},{value:"on('window')",id:"electron-application-event-window",level:3}];function d(e){let n={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.R)(),...e.components};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(n.p,{children:["Electron application representation. You can use ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electron#electron-launch",children:"electron.launch()"})," to obtain the application instance. This instance you can control main electron process as well as work with Electron windows:"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",children:"const { _electron: electron } = require('playwright');\n\n(async () => {\n // Launch Electron app.\n const electronApp = await electron.launch({ args: ['main.js'] });\n\n // Evaluation expression in the Electron context.\n const appPath = await electronApp.evaluate(async ({ app }) => {\n // This runs in the main Electron process, parameter here is always\n // the result of the require('electron') in the main app script.\n return app.getAppPath();\n });\n console.log(appPath);\n\n // Get the first window that the app opens, wait if necessary.\n const window = await electronApp.firstWindow();\n // Print the title.\n console.log(await window.title());\n // Capture a screenshot.\n await window.screenshot({ path: 'intro.png' });\n // Direct Electron console to Node terminal.\n window.on('console', console.log);\n // Click button.\n await window.click('text=Click me');\n // Exit app.\n await electronApp.close();\n})();\n"})}),"\n",(0,l.jsx)(n.hr,{}),"\n",(0,l.jsx)(n.h2,{id:"methods",children:"Methods"}),"\n",(0,l.jsx)(n.h3,{id:"electron-application-browser-window",children:"browserWindow"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.11"}),"\n",(0,l.jsx)("x-search",{children:"electronApplication.browserWindow"}),"\n",(0,l.jsx)(n.p,{children:"Returns the BrowserWindow object that corresponds to the given Playwright page."}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Usage"})}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",children:"await electronApplication.browserWindow(page);\n"})}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Arguments"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.code,{children:"page"})," ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-page",title:"Page",children:"Page"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-browser-window-option-page"}),(0,l.jsx)("a",{href:"#electron-application-browser-window-option-page",class:"list-anchor",children:"#"})]}),"\n",(0,l.jsx)(n.p,{children:"Page to retrieve the window for."}),"\n"]}),"\n"]}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}
1),"<",(0,l.jsx)(n.a,{href:"/docs/next/api/class-jshandle",title:"JSHandle",children:"JSHandle"}),">",(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-browser-window-return"}),(0,l.jsx)("a",{href:"#electron-application-browser-window-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(n.hr,{}),"\n",(0,l.jsx)(n.h3,{id:"electron-application-close",children:"close"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.9"}),"\n",(0,l.jsx)("x-search",{children:"electronApplication.close"}),"\n",(0,l.jsx)(n.p,{children:"Closes Electron application."}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Usage"})}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",children:"await electronApplication.close();\n"})}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-close-return"}),(0,l.jsx)("a",{href:"#electron-application-close-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(n.hr,{}),"\n",(0,l.jsx)(n.h3,{id:"electron-application-context",children:"context"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.9"}),"\n",(0,l.jsx)("x-search",{children:"electronApplication.context"}),"\n",(0,l.jsx)(n.p,{children:"This method returns browser context that can be used for setting up context-wide routing, etc."}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Usage"})}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",children:"electronApplication.context();\n"})}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.a,{href:"/docs/next/api/class-browsercontext",title:"BrowserContext",children:"BrowserContext"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-context-return"}),(0,l.jsx)("a",{href:"#electron-application-context-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(n.hr,{}),"\n",(0,l.jsx)(n.h3,{id:"electron-application-evaluate",children:"evaluate"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.9"}),"\n",(0,l.jsx)("x-search",{children:"electronApplication.evaluate"}),"\n",(0,l.jsxs)(n.p,{children:["Returns the return value of ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electronapplication#electron-application-evaluate-option-expression",children:"pageFunction"}),"."]}),"\n",(0,l.jsxs)(n.p,{children:["If the function passed to the ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electronapplication#electron-application-evaluate",children:"electronApplication.evaluate()"})," returns a ",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),", then ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electronapplication#electron-application-evaluate",children:"electronApplication.evaluate()"})," would wait for the promise to resolve and return its value."]}),"\n",(0,l.jsxs)(n.p,{children:["If the function passed to the ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electronapplication#electron-application-evaluate",children:"electronApplication.evaluate()"})," returns a non-",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description",title:"Serializable",children:"Serializable"})," value, then ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electronapplication#electron-application-evaluate",children:"electronApplication.evaluate()"})," returns ",(0,l.jsx)(n.code,{children:"undefined"}),". Playwright also supports transferring some additional values that are not serializable by ",(0,l.jsx)(n.code,{children:"JSON"}),": ",(0,l.jsx)(n.code,{children:"-0"}),", ",(0,l.jsx)(n.code,{children:"NaN"}),", ",(0,l.jsx)(n.code,{children:"Infinity"}),", ",(0,l.jsx)(n.code,{children:"-Infinity"}),"."]}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Usage"})}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",children:"await electronApplication.evaluate(pageFunction);\nawait electronApplication.evaluate(pageFunction, arg);\n"})}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Arguments"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.code,{children:"pageFunction"})," ",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function",title:"Function",children:"function"})," | ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electron",title:"Electron",children:"Electron"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-evaluate-option-expression"}),(0,l.jsx)("a",{href:"#electron-application-evaluate-option-expression",class:"list-anchor",children:"#"})]}),"\n",(0,l.jsx)(n.p,{children:"Function to be evaluated in the main Electron process."}),"\n"]}),"\n",(0,l.jsxs)(n.li,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.code,{children:"arg"})," ",(0,l.jsx)(n.a,{href:"/docs/next/evaluating#evaluation-argument",title:"EvaluationArgument",children:"EvaluationArgument"})," ",(0,l.jsx)(n.em,{children:"(optional)"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-evaluate-option-arg"}),(0,l.jsx)("a",{href:"#electron-application-evaluate-option-arg",class:"list-anchor",children:"#"})]}),"\n",(0,l.jsxs)(n.p,{children:["Optional argument to pass to ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electronapplication#electron-application-evaluate-option-expression",children:"pageFunction"}),"."]}),"\n"]}),"\n"]}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description",title:"Serializable",children:"Serializable"}),">",(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-evaluate-return"}),(0,l.jsx)("a",{href:"#electron-application-evaluate-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(n.hr,{}),"\n",(0,l.jsx)(n.h3,{id:"electron-application-evaluate-handle",children:"evaluateHandle"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.9"}),"\n",(0,l.jsx)("x-search",{children:"electronApplication.evaluateHandle"}),"\n",(0,l.jsxs)(n.p,{children:["Returns the return value of ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electronapplication#electron-application-evaluate-handle-option-expression",children:"pageFunction"}
1)," as a ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-jshandle",title:"JSHandle",children:"JSHandle"}),"."]}),"\n",(0,l.jsxs)(n.p,{children:["The only difference between ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electronapplication#electron-application-evaluate",children:"electronApplication.evaluate()"})," and ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electronapplication#electron-application-evaluate-handle",children:"electronApplication.evaluateHandle()"})," is that ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electronapplication#electron-application-evaluate-handle",children:"electronApplication.evaluateHandle()"})," returns ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-jshandle",title:"JSHandle",children:"JSHandle"}),"."]}),"\n",(0,l.jsxs)(n.p,{children:["If the function passed to the ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electronapplication#electron-application-evaluate-handle",children:"electronApplication.evaluateHandle()"})," returns a ",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),", then ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electronapplication#electron-application-evaluate-handle",children:"electronApplication.evaluateHandle()"})," would wait for the promise to resolve and return its value."]}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Usage"})}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",children:"await electronApplication.evaluateHandle(pageFunction);\nawait electronApplication.evaluateHandle(pageFunction, arg);\n"})}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Arguments"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.code,{children:"pageFunction"})," ",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function",title:"Function",children:"function"})," | ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electron",title:"Electron",children:"Electron"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-evaluate-handle-option-expression"}),(0,l.jsx)("a",{href:"#electron-application-evaluate-handle-option-expression",class:"list-anchor",children:"#"})]}),"\n",(0,l.jsx)(n.p,{children:"Function to be evaluated in the main Electron process."}),"\n"]}),"\n",(0,l.jsxs)(n.li,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.code,{children:"arg"})," ",(0,l.jsx)(n.a,{href:"/docs/next/evaluating#evaluation-argument",title:"EvaluationArgument",children:"EvaluationArgument"})," ",(0,l.jsx)(n.em,{children:"(optional)"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-evaluate-handle-option-arg"}),(0,l.jsx)("a",{href:"#electron-application-evaluate-handle-option-arg",class:"list-anchor",children:"#"})]}),"\n",(0,l.jsxs)(n.p,{children:["Optional argument to pass to ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-electronapplication#electron-application-evaluate-handle-option-expression",children:"pageFunction"}),"."]}),"\n"]}),"\n"]}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}
1),"<",(0,l.jsx)(n.a,{href:"/docs/next/api/class-jshandle",title:"JSHandle",children:"JSHandle"}),">",(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-evaluate-handle-return"}),(0,l.jsx)("a",{href:"#electron-application-evaluate-handle-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(n.hr,{}),"\n",(0,l.jsx)(n.h3,{id:"electron-application-first-window",children:"firstWindow"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.9"}),"\n",(0,l.jsx)("x-search",{children:"electronApplication.firstWindow"}),"\n",(0,l.jsx)(n.p,{children:"Convenience method that waits for the first application window to be opened."}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Usage"})}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",children:"const electronApp = await electron.launch({\n args: ['main.js']\n});\nconst window = await electronApp.firstWindow();\n// ...\n"})}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Arguments"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.code,{children:"options"})," ",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"})," ",(0,l.jsx)(n.em,{children:"(optional)"}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.code,{children:"timeout"})," ",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type",title:"Number",children:"number"})," ",(0,l.jsx)(n.em,{children:"(optional)"})," ",(0,l.jsx)("font",{size:"2",children:"Added in: v1.33"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-first-window-option-timeout"}),(0,l.jsx)("a",{href:"#electron-application-first-window-option-timeout",class:"list-anchor",children:"#"})]}),"\n",(0,l.jsxs)(n.p,{children:["Maximum time to wait for in milliseconds. Defaults to ",(0,l.jsx)(n.code,{children:"30000"})," (30 seconds). Pass ",(0,l.jsx)(n.code,{children:"0"})," to disable timeout. The default value can be changed by using the ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-browsercontext#browser-context-set-default-timeout",children:"browserContext.setDefaultTimeout()"}),"."]}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,l.jsx)(n.a,{href:"/docs/next/api/class-page",title:"Page",children:"Page"}),">",(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-first-window-return"}),(0,l.jsx)("a",{href:"#electron-application-first-window-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(n.hr,{}),"\n",(0,l.jsx)(n.h3,{id:"electron-application-process",children:"process"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.21"}),"\n",(0,l.jsx)("x-search",{children:"electronApplication.process"}),"\n",(0,l.jsx)(n.p,{children:"Returns the main process for this Electron Application."}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Usage"})}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",children:"electronApplication.process();\n"})}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.a,{href:"https://nodejs.org/api/child_process.html",title:"ChildProcess",children:"ChildProcess"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-process-return"}),(0,l.jsx)("a",{href:"#electron-application-process-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(n.hr,{}),"\n",(0,l.jsx)(n.h3,{id:"electron-application-wait-for-event",children:"waitForEvent"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.9"}),"\n",(0,l.jsx)("x-search",{children:"electronApplication.waitForEvent"}),"\n",(0,l.jsx)(n.p,{children:"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."}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Usage"})}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",children:"const windowPromise = electronApp.waitForEvent('window');\nawait mainWindow.click('button');\nconst window = await windowPromise;\n"})}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Arguments"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.code,{children:"event"})," ",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-wait-for-event-option-event"}),(0,l.jsx)("a",{href:"#electron-application-wait-for-event-option-event",class:"list-anchor",children:"#"})]}),"\n",(0,l.jsxs)(n.p,{children:["Event name, same one typically passed into ",(0,l.jsx)(n.code,{children:"*.on(event)"}),"."]}),"\n"]}),"\n",(0,l.jsxs)(n.li,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.code,{children:"optionsOrPredicate"})," ",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function",title:"Function",children:"function"})," | ",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"})," ",(0,l.jsx)(n.em,{children:"(optional)"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-wait-for-event-option-options-or-predicate"}),(0,l.jsx)("a",{href:"#electron-application-wait-for-event-option-options-or-predicate",class:"list-anchor",children:"#"})]}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.code,{children:"predicate"})," ",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function",title:"Function",children:"function"})]}),"\n",(0,l.jsx)(n.p,{children:"receives the event data and resolves to truthy value when the waiting should resolve."}),"\n"]}),"\n",(0,l.jsxs)(n.li,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.code,{children:"timeout"})," ",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type",title:"Number",children:"number"})," ",(0,l.jsx)(n.em,{children:"(optional)"})]}),"\n",(0,l.jsxs)(n.p,{children:["maximum time to wait for in milliseconds. Defaults to ",(0,l.jsx)(n.code,{children:"30000"})," (30 seconds). Pass ",(0,l.jsx)(n.code,{children:"0"})," to disable timeout. The default value can be changed by using the ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-browsercontext#browser-context-set-default-timeout",children:"browserContext.setDefaultTimeout()"}),"."]}),"\n"]}),"\n"]}),"\n",(0,l.jsx)(n.p,{children:"Either a predicate that receives an event or an options object. Optional."}),"\n"]}),"\n"]}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"}),">",(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-wait-for-event-return"}),(0,l.jsx)("a",{href:"#electron-application-wait-for-event-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(n.hr,{}),"\n",(0,l.jsx)(n.h3,{id:"electron-application-windows",children:"windows"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.9"}),"\n",(0,l.jsx)("x-search",{children:"electronApplication.windows"}),"\n",(0,l.jsx)(n.p,{children:"Convenience method that returns all the opened windows."}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Usage"})}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",children:"electronApplication.windows();\n"})}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array",title:"Array",children:"Array"}),"<",(0,l.jsx)(n.a,{href:"/docs/next/api/class-page",title:"Page",children:"Page"}),">",(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"electron-application-windows-return"}),(0,l.jsx)("a",{href:"#electron-application-windows-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(n.hr,{}),"\n",(0,l.jsx)(n.h2,{id:"events",children:"Events"}),"\n",(0,l.jsx)(n.h3,{id:"electron-application-event-close",children:"on('close')"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.9"}),"\n",(0,l.jsx)("x-search",{children:"electronApplication.on('close')"}),"\n",(0,l.jsx)(n.p,{children:"This event is issued when the application process has been terminated."}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Usage"})}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",children:"electronApplication.on('close', data => {});\n"})}),"\n",(0,l.jsx)(n.hr,{}),"\n",(0,l.jsx)(n.h3,{id:"electron-application-event-console",children:"on('console')"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.42"}),"\n",(0,l.jsx)("x-search",{children:"electronApplication.on('console')"}),"\n",(0,l.jsxs)(n.p,{children:["Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. ",(0,l.jsx)(n.code,{children:"console.log"})," or ",(0,l.jsx)(n.code,{children:"console.dir"}),"."]}),"\n",(0,l.jsxs)(n.p,{children:["The arguments passed into ",(0,l.jsx)(n.code,{children:"console.log"})," are available on the ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-consolemessage",title:"ConsoleMessage",children:"ConsoleMessage"})," event handler argument."]}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Usage"})}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",children:"electronApp.on('console', async msg => {\n const values = [];\n for (const arg of msg.args())\n values.push(await arg.jsonValue());\n console.log(...values);\n});\nawait electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));\n"})}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Event data"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.a,{href:"/docs/next/api/class-consolemessage",title:"ConsoleMessage",children:"ConsoleMessage"})}),"\n"]}),"\n",(0,l.jsx)(n.hr,{}),"\n",(0,l.jsx)(n.h3,{id:"electron-application-event-window",children:"on('window')"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.9"}),"\n",(0,l.jsx)("x-search",{children:"electronApplication.on('window')"}),"\n",(0,l.jsxs)(n.p,{children:["This event is issued for every window that is created ",(0,l.jsx)(n.strong,{children:"and loaded"})," in Electron. It contains a ",(0,l.jsx)(n.a,{href:"/docs/next/api/class-page",title:"Page",children:"Page"})," that can be used for Playwright automation."]}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Usage"})}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",children:"electronApplication.on('window', data => {});\n"})}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"Event data"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.a,{href:"/docs/next/api/class-page",title:"Page",children:"Page"})}),"\n"]})]})}function p(e={}){let{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,l.jsx)(n,{...e,children:(0,l.jsx)(d,{...e})}):d(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.