PrompteryxBeta
    ⌘K
    PlatformSupport
    Menu
    IntroductionInstall Desktop & extensionQuick StartPlatform Overview
    OverviewWhat you can makeAI Browser Agent in the chatModels and AutoConnectorsSchedulesProjectsExplore and publishingShare linksMemory and SkillsPersonal agent (beta)Welcome, settings and skinsPlans, credits and top-upsPrompteryx DesktopGroups (pilot)Phone app (early access)
    OverviewCreating WorkflowsTesting & DebuggingScheduling
    OverviewGetting StartedCommandsRecordingSettingsStructured OutputParallel AgentsTips & Best Practices
    OverviewInstallationSidebar AgentUsing Attached FilesExecute on Current TabExporting to Visual Studio
    Overview
    OverviewOpen PageClickClick CoordinatesFillExtract TextScreenshotWaitPress KeyFocus ElementBlur ElementSelect TextHighlight ElementSet ViewportGet Bounding BoxScrollHoverSelect OptionAssertionsCookiesEvaluate JavaScriptExample Workflows
    OverviewPrompteryx Browser AgentOpenAI
    OverviewSchedule TriggerWebhook Trigger
    OverviewGoogle SheetsGoogle CalendarConnect Hub (3,000+ apps)Example Workflows
    AI Vision SettingsChrome Automation ProfilesCloud BrowserBrowser Profiles & Persistent ContextVideo RecordingExecution LogsSharing & CollaborationEdit History
    Selectors GuideVariables
    Start hereGet an API keyRun the AI browser agentDrive a cloud browserRun workflows from anywhereUse connected apps (Connect Hub)SDK (TypeScript)CLIMCP for AI assistants
    REST APIWebhooksMCP toolsCloud Browser APICloud Browser quickstartMigrate from Browserbasen8nZapierMake.com

    Need help? Contact Support

    1. Documentation
    2. Nodes
    3. Browser Actions
    4. Evaluate JavaScript

    Evaluate JavaScript Node

    Browser Node - Advanced

    Execute 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
    This is an advanced node that requires JavaScript knowledge. Prefer built-in nodes when possible for better maintainability and error handling.
    Parameters
    Configuration options for this node
    code
    JavaScript
    Required

    JavaScript code to run in the page. The node wraps your code in a function, so top-level `return` is allowed.

    Example: return document.title;
    targetVar
    String

    Workflow variable name to store the returned value under. Reference it later with {{yourVarName}} in any downstream node.

    Example: pageTitle, productList

    Usage Examples

    Example 1: Get Page Data
    Extract complex data from the page
    // 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 }));
    Example 2: Modify Page State
    Change page content or trigger JavaScript functions
    // Close all modal dialogs document.querySelectorAll('.modal.open').forEach(modal => { modal.classList.remove('open'); }); return 'Closed all modals';
    Example 3: Call Page Functions
    Invoke existing JavaScript functions on the page
    // Call a React app's state update function if (typeof window.updateCart === 'function') { window.updateCart({ quantity: 5 }); return true; } return false;
    Example 4: Wait for Condition
    Create custom wait logic
    // 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(); });
    Example 5: Interact with localStorage
    Read or write to browser storage
    // 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.

    Best Practices

    Prefer Built-in Nodes
    Before using Evaluate JavaScript, check if a built-in node can do what you need. Built-in nodes have better error handling and are easier to maintain.
    Handle Errors
    Wrap your code in try-catch blocks and return meaningful error messages. Uncaught errors will fail the workflow with potentially cryptic messages.
    Keep Scripts Simple
    Large, complex scripts are hard to debug. Break complex operations into multiple smaller Evaluate JavaScript nodes or combine with other node types.
    Security Warning
    Never execute untrusted user input as JavaScript. Always validate and sanitize any data used in scripts.

    Related Documentation

    Wait for Function

    Wait for JS conditions

    Extract Text Node

    Built-in text extraction

    Variables Guide

    Use JS results in workflow