Skip to content

runWebViewScript ​

Run a JavaScript file in the WebView on screen.

Partial support in Astra Scout

Android only. The step is not available on iOS.

The runWebViewScript command runs a JavaScript file inside the WebView that is on screen, and can keep the result in a variable. Use evalWebViewScript to run an inline snippet instead. It connects to the WebView with the Chrome DevTools protocol, so the WebView must be visible.

Syntax ​

yaml
- runWebViewScript: scripts/read-cart.js
# or
- runWebViewScript:
    file: scripts/read-cart.js
    env:
      ITEM: shoes
    output: CART

Parameters ​

ParameterTypeDescription
fileStringRequired. Path to the JavaScript file. The file is the body of an async function, so use await and return.
envMapValues the script reads from window.__env.
outputStringName of a variable that receives the returned value as text. Later steps read it as ${NAME}.

Behavior ​

  • The script must return a value to fill output. Only a string result is stored.
  • The script is stopped after 10 seconds.
  • The step fails with "No WebView CDP connection" if no inspectable WebView is visible.

Usage example ​

yaml
- runWebViewScript:
    file: scripts/read-heading.js
    output: HEADING
- assertTrue: ${HEADING == "Welcome"}

With scripts/read-heading.js:

js
return document.querySelector('h1').innerText;