﻿<head><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4357510538660394"
     crossorigin="anonymous"></script></head>---
url: https://docs.puppetflow.com/reference/flow-api/navigation.md
---
# Navigation

Page navigation, viewport control, screenshots, cookie persistence and login helpers.

## `$gotoUrl(url, tabName?, options?)` {#goto-url}

Create or reuse a named browser tab, activate it, navigate to a URL, optionally bypass Content Security Policy, and wait for the page to settle. The tab name defaults to `Default`.

```js
await $gotoUrl('https://example.com');

await $gotoUrl('https://example.com', 'Reports', {
  waitUntil: 'domcontentloaded',
  headers: { 'X-Custom': 'value' },
  bypassCSP: false,
});
```

| Option | Default | Description |
| --- | --- | --- |
| `waitUntil` | `'networkidle2'` | Wait condition: `networkidle2` (at most 2 connections for 500 ms), `networkidle0` (no network activity for 500 ms), `load`, `domcontentloaded`, `commit`. |
| `headers` | `{}` | Extra HTTP headers sent with the request. |
| `bypassCSP` | `true` | Bypass Content Security Policy. |
| `timeout` | `30000` | Navigation timeout in milliseconds. Self-hosted instances can override the default with `FLOW_NAVIGATION_TIMEOUT_MS`. |
| `settleDelay` | `2000` | Grace period after navigation in milliseconds. Set to `0` to continue immediately. |

::: warning
Throws if `url` is falsy or not a string. URLs without a scheme are prefixed with `https://`. A timeout is ignored when the browser reached the target URL and the document is already interactive or complete.
:::

Returns the Puppeteer navigation `HTTPResponse`, or `null`.

## `$gotoTab(tabName?)` {#goto-tab}

Switch to an existing named browser tab. The name defaults to `Default`. It throws if the tab does not exist or has been closed.

```js
await $gotoTab('Reports');
```

## `$setViewport(width?, height?)` {#set-viewport}

Set the browser viewport dimensions.

```js
await $setViewport(1920, 1080);
```

Omitted dimensions use the current `$viewportWidth` and `$viewportHeight` values.

## `$screenshot(name?, options?)` {#screenshot}

Take a screenshot of the current page.

```js
await $screenshot('after-login');
await $screenshot('debug-step', { output: false });
```

| Option | Default | Description |
| --- | --- | --- |
| `output` | `true` | Include this screenshot in the run's artifacts. |

Names auto-increment when omitted: `screenshot_00`, `screenshot_01`, etc. Sub-directories in the name are created automatically.

## Cookies

### `$saveCookies(jarName?, options?)` {#save-cookies}

Save all cookies, including HttpOnly cookies, and localStorage by origin for reuse across runs of the same flow.

```js
await $saveCookies('my-session');
await $saveCookies('cookies-only', { persistLocalStorage: false });
```

Default jar name: `"Default"`. `persistLocalStorage` defaults to `true`.

### `$loadCookies(jarName?, options?)` {#load-cookies}

Load a previously saved browser-storage jar, restore its cookies and optionally restore localStorage. Returns `true` on success and `false` if the jar cannot be loaded.

```js
const loaded = await $loadCookies('my-session');
if (!loaded) {
  // jar not found - need to login again
}
```

The default jar is `"Default"`. Set `persistLocalStorage: false` to restore cookies without continuing localStorage persistence.

### `$clearCookies(jarName?)` {#clear-cookies}

Delete a stored browser-storage jar. The jar name defaults to `"Default"`. Clearing the default or active jar also clears live cookies, localStorage, and sessionStorage.

The `Default` jar is restored automatically before `run()` starts, then captured after each navigation and at the end of the flow. Use `$saveCookies()` and `$loadCookies()` when working with named jars or when you need to force a save or restore.

## `$loginRemember(options)` {#login-remember}

Login with cookie persistence. Navigates to `loggedUrl` using the browser storage already restored for the run. If the logged-in marker is not detected, it runs `loginRecipe`, waits for the marker, then saves cookies and localStorage.

```js
await $loginRemember({
  loginUrl: 'https://app.example.com/login',
  loggedUrl: 'https://app.example.com/dashboard',
  loggedMarkerCondition: {
    selectorOrHandle: '.dashboard-header',
  },
  loggedMarkerTimeout: 5000,
  gotoOptions: { waitUntil: 'domcontentloaded' },
  loginRecipe: async () => {
    await $fillInput('#email', 'foo@example.com');
    await $fillInput('#password', 'my_password');
    await $clickElement('#login-btn');
  },
});
```

| Option | Required | Default | Description |
| --- | --- | --- | --- |
| `loginUrl` | yes | - | URL of the login page. |
| `loginRecipe` | yes | - | Async function that performs the login steps. |
| `loggedMarkerCondition` | yes\* | - | Marker object with `selectorOrHandle` and optional text filters, `operator`, and `count`. |
| `loggedMarkerConditionRaw` | yes\* | - | Async function run in the flow context that must return a boolean. |
| `loggedUrl` | yes | - | URL to navigate to for checking login state. |
| `loggedMarkerTimeout` | no | `5000` | Timeout (ms) for the marker check. |
| `gotoOptions` | no | `{ waitUntil: 'domc