Actions5
Function → Execute
AI-generatedOverview
This node integrates with the Browserless API to perform browser automation tasks such as executing custom JavaScript code in a browser context, scraping content, capturing screenshots, and generating PDFs. Specifically, the Function - Execute operation allows users to run arbitrary JavaScript code within a browser environment managed by Browserless. This is useful for scenarios where you need to interact programmatically with web pages beyond simple scraping — for example, running complex scripts that manipulate page content, extract dynamic data, or automate workflows inside a headless browser.
Practical examples include:
- Running custom scripts to extract data from single-page applications.
- Automating form submissions or interactions on websites.
- Executing JavaScript to transform or analyze page content before returning results.
Properties
| Name | Meaning |
|---|---|
| Code | The JavaScript code to execute inside the browser context. |
| Context | A JSON object representing the context or variables passed into the executed code. |
| Detached | Boolean flag indicating whether the browser session should be detached (run independently). |
| Browser Options | Collection of optional settings controlling browser behavior: |
| - BlockAds | Whether to block advertisement network traffic (true/false). |
| - Headless | Whether the browser runs in headless mode (true/false). |
| - Ignore HTTPS Errors | Whether to ignore HTTPS errors during page loads and network calls (true/false). |
| - Stealth | Enables stealth mode to help avoid bot detection (true/false). |
| - User Data Dir | Path to reuse previous session data like cookies and local storage (string). |
| - TrackingId | Arbitrary tracking ID for correlating sessions or API calls (string). |
| - Keep Alive | Time in milliseconds to keep the browser running after the session ends (string). |
| - Flags | Command-line flags passed directly to Chrome on startup (string). |
Output
The output contains a json field with the result of the executed JavaScript code returned from the Browserless API. The structure depends on what the executed code returns but generally includes any data or objects produced by the script.
No binary data is output for this operation.
Example output JSON might look like:
{
"result": { /* data returned by the executed code */ }
}
Dependencies
- Requires an active connection to the Browserless API service.
- Needs an API authentication token configured in n8n credentials to authorize requests.
- The node uses the Browserless API endpoint to execute JavaScript code remotely in a browser environment.
Troubleshooting
Common issues:
- Invalid or malformed JavaScript code in the "Code" property can cause execution failures.
- Incorrectly formatted JSON in the "Context" property will cause parsing errors.
- Network or authentication errors if the API key is missing or invalid.
- Detached mode may lead to unexpected behavior if the session is not properly managed.
Error messages:
"SyntaxError"or similar indicates problems in the provided JavaScript code."Invalid JSON"errors point to issues parsing the context input.- Authentication errors suggest checking the API key credential setup.
Resolutions:
- Validate and test JavaScript code separately before using it in the node.
- Ensure the context JSON is well-formed.
- Verify API credentials and network connectivity.
- Use detached mode only when necessary and understand its implications.