← Back to recipes

Open a page and inspect it

Create a browser tab, navigate to a URL, read the page title, and log the final URL.

Browser Automation Beginner JavaScript open_a_page.js

Prerequisites

None.

Expected result

Guida opens a tab, navigates to example.com, logs the page title, and logs the final URL.

Source example

open_a_page.js

Use this as the smallest useful browser automation script. It creates a tab, navigates, and reads basic page state from the active browser.

// Open a Page — Navigate the browser to a URL
//
// This script shows how to navigate to a URL and wait
// for the page to fully load before continuing.
const url = "https://example.com";
// Ensure we have a browser tab to work with
await g.tabs.newBrowserTab();
g.log("Navigating to " + url + "...");
// Navigate and wait for the page to load
await g.nav.navigateToUrl(url);
g.log("Page loaded!");
// Read the page title via executeJS
const title = await g.page.executeJS("document.title");
if (title) {
g.log("Page title: " + title);
}
// Get the final URL (might differ if redirected)
const finalUrl = await g.page.getUrl();
g.log("Final URL: " + finalUrl);