Docs

Your First Automation

Time to write your own browser automation — about six lines — and save it as a reusable command. Open the guided project with File → New Default Window to do this hands-on.

This is the in-app kind of automation (a .js script you run against a browser tab). For cloud workflows built with @tranquil/sdk, see Your First Workflow.

Dev preview — not stable. Tranquil is in early, active development. Everything here — APIs, interfaces, and behavior — is provisional and will change before a stable release, often without notice or backward compatibility. Don’t build anything you depend on against it.

1. Create the file

In the tree, right-click Automations/browser/New File → name it my-first.js.

2. Write the three moves

// My first automation: count the paragraphs on the page.
const tab = await tranquil.getActiveTab();
const count = await tab.evaluate(() => {
  return document.querySelectorAll('p').length;
});
tranquil.notify(`This page has ${count} paragraph(s).`, 'success');

The () => { … } passed to evaluate runs inside the page; the rest runs in Tranquil.

3. Run it

  1. Open a browser tab on any page.
  2. Click back into my-first.js so the editor is focused.
  3. Press Cmd-Shift-R.

A notification reports the paragraph count. Change 'p' to 'a' or 'img', select the changed line, and press Cmd-Shift-R to run just that line.

4. Save it as a command

  1. With my-first.js focused, run “Automations: Register Current File” from the command palette (Cmd-Shift-P).
  2. The command is named automatically from the file namemy-first.js registers as Automations: My First.

To give a command a clearer name, name the file for what it does: count-paragraphs.js registers as Automations: Count Paragraphs. Run it from the palette any time; it targets the active tab and persists across restarts.

Going further

  • Edit any script in Automations/browser/ to make it your own.
  • Try cloud workflows — the headless, scheduled kind that run on the Engine rather than in the app. Sample workflows are coming to Automations/workflows/; for now, see Your First Workflow.