Execute Javascript
guides1 section
🧠 Execute JavaScript (Browser Action)
Run custom JavaScript code directly within the page context during a scraping session. Perfect for DOM manipulation, extracting data, or triggering dynamic interactions.
🧠 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 | Required | Description |
|---|---|---|
code |
✅ Yes | The JavaScript code to execute. This must be a valid JavaScript string. |
🧪 Example Request (cURL)
curl -X POST "https://publisher.scrappey.com/api/v1?key=API_KEY" \
-H "Content-Type: application/json" \
-d '{
"cmd": "request.get",
"url": "https://example.com",
"browserActions": [
{
"type": "execute_js",
"code": "console.log('Hello, world!');"
}
]
}'
🧠 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, ortypefor dynamic control flows.