PageSourceSearch

https://webdriver.io/assets/js/b8d3f1cc.8cae4f02.js

js webdriver.io collected 2026-09-24 08:34:27 UTC 6,393 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[18611],{22002:(e,t,n)=>{n.d(t,{R:()=>c,x:()=>o});var s=n(7378);const r={},i=s.createContext(r);function c(e){const t=s.useContext(i);return s.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:c(e.components),s.createElement(i.Provider,{value:t},e.children)}},97654:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>o,default:()=>u,frontMatter:()=>c,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"api/browser/executeAsync","title":"executeAsync","description":"The executeAsync command is deprecated and will be removed in a future version.","source":"@site/docs/api/browser/_executeAsync.md","sourceDirName":"api/browser","slug":"/api/browser/executeAsync","permalink":"/docs/api/browser/executeAsync","draft":false,"unlisted":false,"editUrl":"https://github.com/webdriverio/webdriverio/edit/main/packages/webdriverio/src/commands/browser/executeAsync.ts","tags":[],"version":"current","frontMatter":{"id":"executeAsync","title":"executeAsync","custom_edit_url":"https://github.com/webdriverio/webdriverio/edit/main/packages/webdriverio/src/commands/browser/executeAsync.ts"},"sidebar":"api","previous":{"title":"execute","permalink":"/docs/api/browser/execute"},"next":{"title":"getCookies","permalink":"/docs/api/browser/getCookies"}}');var r=n(86106),i=n(22002);const c={id:"executeAsync",title:"executeAsync",custom_edit_url:"https://github.com/webdriverio/webdriverio/edit/main/packages/webdriverio/src/commands/browser/executeAsync.ts"},o=void 0,a={},d=[{value:"Usage",id:"usage",level:2},{value:"Parameters",id:"parameters",level:2},{value:"Examples",id:"examples",level:2},{value:"Returns",id:"returns",level:2}];function l(e){const t={admonition:"admonition",code:"code",em:"em",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.admonition,{type:"warning",children:(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"executeAsync"})," command is deprecated and will be removed in a future version.\nPlease use the ",(0,r.jsx)(t.code,{children:"execute"})," command instead as it provides better support for\nerror handling via ",(0,r.jsx)(t.code,{children:"async"}),"/",(0,r.jsx)(t.code,{children:"await"}),"."]})}),"\n",(0,r.jsx)(t.p,{children:"Inject a snippet of JavaScript into the page for execution in the context of the currently selected\nframe. The executed script is assumed to be asynchronous and must signal that is done by invoking\nthe provided callback, which is always provided as the final argument to the function. The value\nto this callback will be returned to the client."}),"\n",(0,r.jsx)(t.p,{children:"Asynchronous script commands may not span page loads. If an unload event is fired while waiting\nfor a script result, an error should be returned to the client."}),"\n",(0,r.jsx)(t.p,{children:"The script argument defines the script to execute in the form of a function body. The function will\nbe invoked with the provided args array and the values may be accessed via the arguments object\nin the order specified. The final argument will always be a callback function that must be invoked\nto signal that the script has finished."}),"\n",(0,r.jsx)(t.p,{children:"Arguments may be any JSON-primitive, array, or JSON object. JSON objects that define a WebElement\nreference will be converted to the corresponding DOM element. Likewise, any WebElements in the script\nresult will be returned to the client as WebElement JSON objects."}),"\n",(0,r.jsx)(t.admonition,{type:"caution",children:(0,r.jsxs)(t.p,{children:["Please use ",(0,r.jsx)(t.code,{children:"execute"})," instead"]})}),"\n",(0,r.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",children:"await browser.executeAsync(script, arguments)\n"})}),"\n",(0,r.jsx)(t.h2,{id:"parameters",children:"Parameters"}),"\n",(0,r.jsxs)(t.table,{children:[(0,r.jsx)(t.thead,{children:(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.th,{children:"Name"}),(0,r.jsx)(t.th,{children:"Type"}),(0,r.jsx)(t.th,{children:"Details"})]})}),(0,r.jsxs)(t.tbody,{children:[(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"script"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"String, Function"})}),(0,r.jsx)(t.td,{children:"The script to execute."})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"arguments"}),(0,r.jsx)("br",{}),(0,r.jsx)(t.em,{children:"optional"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"*"})}),(0,r.jsx)(t.td,{children:"script arguments"})]})]})]}),"\n",(0,r.jsx)(t.h2,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:'title="executeAsync.js"',children:"it('should execute async JavaScript on the page', async () => {\n    await browser.setTimeout({ script: 5000 })\n    const result = await browser.executeAsync(function(a, b, c, d, done) {\n        // browser context - you may 
1not access client or console\n        setTimeout(() => {\n            done(a + b + c + d)\n        }, 3000);\n    }, 1, 2, 3, 4)\n    // node.js context - client and console are available\n    console.log(result) // outputs: 10\n});\n\n"})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:'title="executeAsync.ts"',children:"// explicitly type the return value of the script to ensure type safety\nconst result: number = await browser.executeAsync(function(a, b, c, d, done) {\n    // browser context - you may not access client or console\n    setTimeout(() => {\n        done(a + b + c + d)\n    }, 3000);\n}, 1, 2, 3, 4)\n"})}),"\n",(0,r.jsx)(t.h2,{id:"returns",children:"Returns"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.strong,{children:"<*>"}),"\n",(0,r.jsxs)(t.strong,{children:[(0,r.jsx)("code",{children:(0,r.jsx)("var",{children:"return"})}),":"]}),"              The script result."]}),"\n"]})]})}function u(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(l,{...e})}):l(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.