Evaluate JavaScript Node
Browser Node - AdvancedExecute custom JavaScript code in the browser context
Overview
The Evaluate JavaScript node allows you to run custom JavaScript code directly in the web page's browser context. This gives you full access to the page's DOM, JavaScript variables, and APIs for complex operations that aren't covered by other nodes.
Advanced Node
codeJavaScript code to run in the page. The node wraps your code in a function, so top-level `return` is allowed.
return document.title;targetVarWorkflow variable name to store the returned value under. Reference it later with {{yourVarName}} in any downstream node.
pageTitle, productListUsage Examples
// Extract all product info from a listing
return Array.from(document.querySelectorAll('.product')).map(el => ({
name: el.querySelector('.name')?.textContent,
price: el.querySelector('.price')?.textContent,
url: el.querySelector('a')?.href
}));// Close all modal dialogs
document.querySelectorAll('.modal.open').forEach(modal => {
modal.classList.remove('open');
});
return 'Closed all modals';// Call a React app's state update function
if (typeof window.updateCart === 'function') {
window.updateCart({ quantity: 5 });
return true;
}
return false;// Wait for a React app to finish loading
return new Promise((resolve) => {
const checkLoaded = () => {
if (document.querySelector('[data-loaded="true"]')) {
resolve(true);
} else {
setTimeout(checkLoaded, 100);
}
};
checkLoaded();
});// Get user preferences from localStorage
return JSON.parse(localStorage.getItem('userPrefs') || '{}');Storing & Using the Result
Set Target Variable to capture whatever your script returns. The value then becomes available to every node after this one as {{yourVarName}}(simple substitution) or as {{$('Node Label').item.json.result}}(expression form that looks the value up by the node's label).
// Script — Target Variable: pageInfo
return JSON.stringify({
title: document.title,
inputCount: document.querySelectorAll('input').length,
url: location.href
});In a downstream Display Message node you'd then write:
Page data: {{pageInfo}}Tip: if you return a deeply-nested object, prefer JSON.stringify(...). Execution history storage has a nested-object depth limit, and stringifying sidesteps it.
Return Values
Serializable Returns Only
Return values must be JSON-serializable. You can return:
- Strings, numbers, booleans, null
- Arrays and plain objects
- Promises (will be awaited)
You cannot return DOM elements, functions, or circular objects.