Trawl

Account & sessions

Give a scrap a login or a saved session, and it reads pages behind a login. Store the account once; Trawl keeps it encrypted, puts the session back on the browser before each run, and your script logs in only when it has to.

1. Store a session or a login

Three ways, from the one that does the most for you:

  1. trawl scraps account session capture <id> (best): a real Chrome window opens at the scrap's URL. Log in as you always do, 2FA included, then press Enter in the terminal. The CLI reads the session (cookies and each site's local storage) and uploads it. It needs a local terminal with a screen: not headless, not CI, not plain SSH.

    You stay logged in as yourself: Trawl never sees your password, only the session. You are responsible for using that session lawfully; this is not legal advice.

  2. Settings → Account in the web app: a username and password, or a session.

  3. trawl scraps account session set <id> -c <file>: uploads a session you already have, either a Puppeteer cookie list or a { cookies, origins } file (the shape session capture makes).

Each upload replaces the whole stored session. All commands: CLI.

2. Use it in your script

Trawl puts the stored session on the browser before your script's first page load: cookies on the whole browser, local storage on each page, popups included. So your script does not restore cookies itself. Its job is to check whether the page is logged in, and log in only if not:

saveSession(cookies) is a helper in the script (not part of TRAWL.account). It stores the cookies, encrypted, and keeps any local storage already stored. Use it after a login your script did; use session capture or session set when you need local storage too.

Node
var page = await browser.newPage();

// The stored session is already on this page: check for a logged-in marker.
await page.goto('https://example.com/dashboard', { waitUntil: 'domcontentloaded' });
const loggedIn = await page.$('.account-menu') !== null;

if (!loggedIn) {
  await page.goto('https://example.com/login', { waitUntil: 'domcontentloaded' });
  await page.type('#username', TRAWL.account.username);
  await page.type('#password', TRAWL.account.password);
  await Promise.all([
    page.click('button[type=submit]'),
    page.waitForNavigation({ waitUntil: 'networkidle2' }),
  ]);
  // Keep the new cookies so the next run skips the login.
  await saveSession(await page.cookies());
}

What the script gets

TRAWL.account.* (the bare account.* still works as an old alias):

Field Type Description
TRAWL.account.username string The stored username, or null on a session-only account.
TRAWL.account.password string The stored password, or null on a session-only account.
TRAWL.account.session object Always there once an account is set.
TRAWL.account.session.cookies Cookie[] Puppeteer cookies. [] before the first session.
TRAWL.account.session.origins Origin[] { origin, localStorage: [{name, value}] } per site. [] when none.
TRAWL.account.session.savedAt Date | null When the session was last saved.
TRAWL.account.session.expiresAt Date | null After this date the session is cleared; the username and password stay.

An empty list is still truthy in JavaScript: to know whether there is a session, test TRAWL.account.session.cookies.length.

The account never comes from the run call: its body only carries TRAWL.* parameters (see Parameters).

Session lifecycle

  1. First run: no session yet, the script logs in and calls saveSession. Or you captured a session first, and it is already there.
  2. Next runs: Trawl puts the stored session back before the script starts.
  3. Expiry: once expiresAt is past, the session is cleared (cookies and origins come back as []) and the next run logs in again.
  4. Clear by hand: Settings → Account → Clear session.

Credentials and sessions are always encrypted at rest.

Session rules

A session you upload is checked before it is stored. A bad cookie is a 422 with a clear message, not a silent failure later:

Rule Detail
cookies A non-empty list. Each cookie needs a domain.
expires Unix seconds. -1 (a « session cookie » in some exports) is dropped.
sameSite Written Strict / Lax / None; unspecified is left out. None needs secure: true.
Unknown cookie fields Dropped.
origins[].origin A bare origin (scheme://host[:port]), no path or query.
origins[].localStorage A list of { name, value } text pairs.

Run fields: accountUsed / sessionUsed

Each run in the history has two flags:

  • accountUsed: true when the run was sent with a username and password.
  • sessionUsed: true when at least one stored cookie was put on the browser (by Trawl, or by an old script that still restores cookies itself).

They are independent: a first login is accountUsed only, a reused session is both, and a session-only account is sessionUsed only.

Not a guaranteed fix

A fresh session is the right first move on a site that asks you to log in, but it may not be enough: some sites also block a session that comes from a datacenter IP. A home-IP proxy tier is the fix there.


See also: Advanced scraping · Parameters · Data Quality · AI Features

Next step → Security