Skip to content
Figranium logo

JavaScript Execution

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 com...

The Run JavaScript Block#

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

Execution Context#

The code runs directly in the browser console (via page.evaluate()).

  • Scope: Global window object is available.
  • DOM: Full access to document, querySelector, etc.
  • Variables: Access runtime variables using {$varName} syntax.

Return Values#

The return value of your script is captured and stored in block.output.

  • String/Number/Boolean: Saved directly.
  • Object/Array: Automatically JSON stringified.
  • Promise: figranium awaits the promise resolution.

Examples#

1. Extract Text Content

return document.querySelector(".price").innerText;

2. Scroll to Bottom

window.scrollTo(0, document.body.scrollHeight);
return true; // Simple confirmation

3. Complex Logic

const items = document.querySelectorAll(".item");
let total = 0;
items.forEach((item) => {
  const price = parseFloat(item.dataset.price);
  if (price > 100) total += price;
});
return total;

4. Using Variables

const user = "{$username}"; // Injected by figranium
document.cookie = `user=${user}; path=/`;

Security Note#

Scripts run with the same privileges as the page itself. Be cautious when executing untrusted code or exposing sensitive variables.