Spotted something off?Report on Discord
guides

Execute Javascript

Run custom JavaScript code directly within the page context during a Scrappey browser session.

Updated May 28, 2025

Run custom JavaScript code directly within the page context during a scraping session.

Command

"execute_js"

This action injects and runs your JavaScript code inside the target page, just like a script executed from the browser's console.

Parameters

Parameter Type Required Description
code string Yes The JavaScript code to execute. This must be a valid JavaScript string.
dontReturnValue boolean No Set to true if the script has no return value. By default the evaluated result is captured.

Return Values

The result of each execute_js action is pushed onto the javascriptReturn array (in execution order). You can reference a previous result inside a later action using the {javascriptReturn[n]} placeholder, where n is the zero-based index:

json13 lines

Example

bash12 lines

Notes

Use Case Ideas:

  • Extract values or text content from the DOM.
  • Trigger JavaScript events like clicks or input changes.
  • Interact with pages that use frameworks like React or Vue by invoking component methods.
  • Modify the DOM before parsing the response.

Tips:

  • Avoid long-running loops or infinite scripts β€” they may cause timeouts.
  • Escape special characters properly when sending code inside JSON.
  • You can combine this with if, scroll, click, or type for dynamic control flows.

Go deeper in the Scrappey knowledge base: