Skip to main content
Figranium allows you to execute custom JavaScript in the browser context at any point in a task. This is the most powerful feature for handling complex logic, data transformation, unsupported interactions, and dynamic content.

The Run JavaScript Block

Add a Run JavaScript action block (internally javascript) to your task.

Execution Context

The code runs directly in the browser page context (via Playwright’s page.evaluate()).
  • Scope: Full access to the global window object.
  • DOM: Full access to document, querySelector, querySelectorAll, etc.
  • Variables: Access runtime variables using {$varName} syntax — they are injected as string literals before evaluation.
  • Async: await is supported. Figranium awaits promise resolution automatically.

Return Values

The return value of your script is captured and stored in block.output, which can be used by subsequent blocks. Access the result in later blocks with {$block.output} or in conditions with block.output.

Examples

Extract Text Content

Extract Multiple Values

Scroll to Bottom of Page

Scroll to Load More Content (Infinite Scroll)

Click an Element That Doesn’t Respond to Standard Click

Some sites use custom event handlers. Dispatch a native event:

Manipulate Local Storage

Using Variables

Variables are injected as string literals before evaluation. Use them in expressions:

Fetch Data from an API Inside the Page Context

Since the script runs in the browser, you can make fetch calls to APIs that the page has access to (bypassing CORS since you’re inside the same origin):

Extract a Table as JSON

Wait for an Element with a Custom Timeout

The javascript block runs synchronously by default. You can add custom polling logic:

Chaining JavaScript Blocks

Use block.output to pass data between JavaScript blocks:

Extraction Scripts vs. JavaScript Action Blocks

Figranium has two places where you can run JavaScript: For final data collection, prefer the Extraction Script field in task settings. Use JavaScript action blocks for mid-flow decisions and interactions.

Security Considerations

  • Scripts run with the same privileges as the target page.
  • Variables injected via {$varName} are literal string substitutions — avoid injecting user-controlled data into scripts directly to prevent unintended code execution.
  • The JavaScript action block runs in the browser context, not in Node.js. You cannot access the file system or Node.js APIs from within these blocks.
  • For complex data processing that needs Node.js features, use the Extraction Script which runs through Figranium’s sandboxed JSDOM environment. The sandbox is hardened against prototype-chain escape techniques, so extraction scripts cannot break out to access the host Node.js runtime.
  • Data objects passed into the sandbox are read-only. You cannot set, define, or delete properties on them. If you need to transform data, copy values into new objects you create within your script. See Sandbox isolation for details.