Skip to content

🧭 Navigation API β€” Page Navigation & Info ​

Control page navigation, get page information, and wait for page loads. Essential for moving around websites and capturing page state.

⚠️ Version Requirement: Binary v0.1.14+ | Library v0.0.21+


Overview ​

MethodPurposeUse Case
navigate()Go to a URLLoad a page
reload()Refresh current pageGet fresh content
goBack()Previous pageBrowser history
goForward()Next pageBrowser history
title()Get page titlePage identification
url()Get current URLTrack location
content()Get full HTMLPage analysis
waitForNavigation()Wait for page loadAfter clicks/forms
waitForSelector()Wait for elementWait for content to load

Basic Navigation ​

Navigates to a URL. If no URL is provided, uses the registered URL from register().

ts
// Navigate to registered URL
await piggy.books.navigate();

// Navigate to a different URL
await piggy.books.navigate("https://books.toscrape.com/catalogue/page-2.html");
await piggy.books.waitForSelector(".product_pod");
console.log("Page 2:", piggy.books.url());
// Page 2: https://books.toscrape.com/catalogue/page-2.html

reload() ​

Reloads the current page.

ts
await piggy.books.reload();
console.log("Reloaded:", await piggy.books.title());
// Reloaded: All products | Books to Scrape - Sandbox

goBack() ​

Goes back one page in history.

ts
await piggy.books.goBack();
console.log("Back to:", piggy.books.url());
// Back to: https://books.toscrape.com/

goForward() ​

Goes forward one page in history.

ts
await piggy.books.goForward();
console.log("Forward to:", piggy.books.url());
// Forward to: https://books.toscrape.com/catalogue/page-2.html

Page Information ​

title() ​

Returns the current page title. Async.

ts
const title = await piggy.books.title();
console.log("Page title:", title);
// Page title: All products | Books to Scrape - Sandbox

url() ​

Returns the current URL. Synchronous β€” no await needed.

ts
console.log("Page 1:", piggy.books.url());
// Page 1: https://books.toscrape.com

content() ​

Returns the full HTML of the page.

ts
const html = await piggy.books.content();
console.log("HTML preview:", html.slice(0, 200));
// HTML preview: <!DOCTYPE html><!--[if lt IE 7]>...

Waiting ​

waitForSelector(selector, timeout?) ​

Waits for an element to appear in the DOM. Default timeout 10000ms.

ts
await piggy.books.waitForSelector(".product_pod");
console.log("Products visible βœ“");

waitForNavigation() ​

Waits for the page to finish loading after an action that triggers navigation.

ts
await piggy.books.click("a[href='/catalogue/page-2.html']");
await piggy.books.waitForNavigation();
console.log(piggy.books.url());

Custom Wait with evaluate() ​

For complex conditions, use evaluate() with a Promise:

ts
// Wait for exactly 20 products to load
await piggy.books.evaluate(() => {
  return new Promise<void>((resolve) => {
    const check = () => {
      if (document.querySelectorAll(".product_pod").length >= 20) resolve();
      else setTimeout(check, 100);
    };
    check();
  });
});
console.log("All 20 products loaded βœ“");

Full Example ​

ts
import piggy from "nothing-browser";
import path from "path";

const binaryPath = path.resolve(import.meta.dir, "../a/nothing-browser-headful.exe");

await piggy.launch({ mode: "tab", binary: binaryPath });
await piggy.register("books", "https://books.toscrape.com");

// Navigate to registered URL
await piggy.books.navigate();
console.log("Page 1:", piggy.books.url());

// Navigate to a different URL
await piggy.books.navigate("https://books.toscrape.com/catalogue/page-2.html");
await piggy.books.waitForSelector(".product_pod");
console.log("Page 2:", piggy.books.url());

// Go back
await piggy.books.goBack();
console.log("Back to:", piggy.books.url());

// Go forward
await piggy.books.goForward();
console.log("Forward to:", piggy.books.url());

// Reload
await piggy.books.reload();
console.log("Reloaded:", await piggy.books.title());

// Wait for elements
await piggy.books.waitForSelector(".product_pod");
console.log("Products visible βœ“");

// Custom JS condition
await piggy.books.evaluate(() => {
  return new Promise<void>((resolve) => {
    const check = () => {
      if (document.querySelectorAll(".product_pod").length >= 20) resolve();
      else setTimeout(check, 100);
    };
    check();
  });
});
console.log("All 20 products loaded βœ“");

// Get full page HTML
const html = await piggy.books.content();
console.log("\nHTML preview:", html.slice(0, 200));

await piggy.close();

Expected Output ​

Page 1: https://books.toscrape.com
Page 2: https://books.toscrape.com/catalogue/page-2.html
Back to: https://books.toscrape.com/
Forward to: https://books.toscrape.com/catalogue/page-2.html
Reloaded: All products | Books to Scrape - Sandbox
Products visible βœ“
All 20 products loaded βœ“

HTML preview: <!DOCTYPE html><!--[if lt IE 7]>      <html lang="en-us" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->...

API Reference ​

MethodParametersReturnsDescription
navigate(url?)url?: stringPromise<void>Navigate to URL
reload()β€”Promise<void>Reload current page
goBack()β€”Promise<void>Go back in history
goForward()β€”Promise<void>Go forward in history
waitForNavigation()β€”Promise<void>Wait for page load
title()β€”Promise<string>Get page title
url()β€”string (sync)Get current URL
content()β€”Promise<string>Get full page HTML
waitForSelector(selector, timeout?)selector: string, timeout?: numberPromise<void>Wait for element

Next Steps ​


Nothing Ecosystem Β· Ernest Tech House Β· Kenya Β· 2026

MIT Licensed | Built by Ernest Tech House Β· Kenya Β· 2026