Skip to main content

Run Script

Executes custom JavaScript code in the browser context. Provides full access to the DOM and browser APIs for advanced automation scenarios.

Common Properties​

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing the node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If Continue On Error property is true, no error is caught when the project is executed, even if the Catch node is used.

Input​

  • Browser ID - The browser session identifier from the Open Browser node.
  • Function - JavaScript code to execute in the browser. The code has access to a msg variable containing the current message context.

Output​

  • Result - The return value from the executed JavaScript code. Returns the value of the last expression or explicit return statement.

Examples​

Simple Script​

Browser ID: {{browser_id}}
Function:
return document.title;

Output: {{script_result}}

Scroll to Bottom​

Browser ID: {{browser_id}}
Function:
window.scrollTo(0, document.body.scrollHeight);
return true;
Browser ID: {{browser_id}}
Function:
const links = Array.from(document.querySelectorAll('a'));
return links.map(a => a.href);

Output: {{links_array}}

Access Message Data​

Browser ID: {{browser_id}}
Function:
// msg variable contains the message context
const productId = msg.product_id;
const element = document.querySelector(`[data-id="${productId}"]`);
return element ? element.textContent : null;

Output: {{product_name}}

Modify Page Content​

Browser ID: {{browser_id}}
Function:
document.querySelector('h1').textContent = 'Modified Title';
return 'Title changed';

Wait for Element with JavaScript​

Browser ID: {{browser_id}}
Function:
return new Promise((resolve) => {
const interval = setInterval(() => {
const element = document.querySelector('#dynamic-content');
if (element) {
clearInterval(interval);
resolve(element.textContent);
}
}, 100);
});

Click Hidden Element​

Browser ID: {{browser_id}}
Function:
const element = document.querySelector('#hidden-button');
element.click();
return 'Clicked';

JavaScript Context​

The script executes in the browser's JavaScript context with access to:

  • DOM APIs - document, window, all standard JavaScript
  • msg variable - Current message data from the workflow
  • return statement - Return values back to the workflow
  • Promises - Async operations are supported

Tips​

  • Use return statement to pass data back to the workflow
  • Access workflow data through the msg variable
  • Ideal for operations not available in standard nodes
  • Can manipulate page elements directly
  • Supports both synchronous and asynchronous code
  • Use console.log for debugging (visible in browser console)
  • Errors will be caught and reported to the workflow

Common Errors​

  • "Browser ID cannot be empty" - Connect to an Open Browser node
  • "JavaScript execution failed" - Syntax error in the script. Check the error message for details
  • "Browser session not found" - Ensure the Open Browser node has run successfully