The Run JavaScript Block
Add a Run JavaScript action block (internallyjavascript) to your task.
Execution Context
The code runs directly in the browser page context (via Playwright’spage.evaluate()).
- Scope: Full access to the global
windowobject. - DOM: Full access to
document,querySelector,querySelectorAll, etc. - Variables: Access runtime variables using
{$varName}syntax — they are injected as string literals before evaluation. - Async:
awaitis supported. Figranium awaits promise resolution automatically.
Return Values
The return value of your script is captured and stored inblock.output, which can be used by subsequent blocks.
| Return type | How it’s stored |
|---|---|
| String | Stored as-is |
| Number | Stored as-is |
| Boolean | Stored as-is |
| Object | JSON-stringified |
| Array | JSON-stringified |
| Promise | Awaited, then stored |
undefined | Empty string |
{$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 makefetch 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
Thejavascript block runs synchronously by default. You can add custom polling logic:
Chaining JavaScript Blocks
Useblock.output to pass data between JavaScript blocks:
Extraction Scripts vs. JavaScript Action Blocks
Figranium has two places where you can run JavaScript:| JavaScript Action Block | Extraction Script | |
|---|---|---|
| When it runs | At a specific step in the task flow | After all actions complete |
| Output | block.output | Task’s result.data |
| Use case | Mid-flow logic, intermediate data | Final data extraction |
| DOM access | Full | Full |
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.