Implementation:Getgauge Taiko Goto
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, Testing, Navigation |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for navigating the browser to a specified URL with configurable timeout and header options, provided by the Taiko library.
Description
goto is the primary page navigation function in Taiko. It instructs the browser to navigate to a given URL using the CDP Page.navigate command and waits for the page to finish loading. The function includes several intelligent behaviors:
- Automatic protocol prefix — if the provided URL does not include a protocol scheme (e.g.,
http://orhttps://), Taiko automatically prependshttp://. This allows users to writegoto('example.com')instead ofgoto('http://example.com'). - Navigation waiting — by default,
gotowaits for the page to fully load before resolving. This includes waiting for thePage.loadEventFiredandPage.frameStoppedLoadingevents. - Response tracking — the function tracks HTTP responses via the CDP Network domain and returns status information including the HTTP status code, status text, and any redirect responses encountered during navigation.
- Custom headers — allows setting custom HTTP headers for the navigation request, useful for authentication tokens or API testing.
- Configurable timeout — the
navigationTimeoutoption controls how long Taiko waits for the page to load before throwing a timeout error.
Usage
Call goto(url) after openBrowser() to navigate to a web page. It is the standard way to load a page in both scripts and REPL sessions. The function should be awaited to ensure the page is fully loaded before performing subsequent interactions.
Code Reference
Source Location
- Repository: Taiko
- File:
lib/taiko.js - Lines: L765-780
Signature
module.exports.goto = async (url, options = { navigationTimeout: defaultConfig.navigationTimeout }) => { ... }
Import
const { goto } = require('taiko');
I/O Contract
Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| url | string | Yes | — | The URL to navigate to. If no protocol scheme is provided, http:// is automatically prepended.
|
| options | Object | No | { navigationTimeout: 30000 } |
Configuration object for navigation behavior. |
| options.navigationTimeout | number | No | 30000 |
Maximum time in milliseconds to wait for the page to load before throwing a timeout error. |
| options.headers | Object | No | — | Custom HTTP headers to include with the navigation request. Keys are header names, values are header values. |
| options.waitForNavigation | boolean | No | true |
Whether to wait for the page to fully load before resolving. When false, the function resolves immediately after issuing the navigate command.
|
| options.waitForEvents | string[] | No | — | Specific CDP events to wait for before considering navigation complete. Overrides the default load event behavior. |
| options.waitForStart | number | No | 100 |
Time in milliseconds to wait for the navigation to actually start after issuing the command. |
Outputs
| Name | Type | Description |
|---|---|---|
| (return) | Promise<Object> | Resolves with a response object containing navigation results. |
| .url | string | The final URL after navigation (may differ from input due to redirects). |
| .status.code | number | The HTTP status code of the response (e.g., 200, 301, 404).
|
| .status.text | string | The HTTP status text of the response (e.g., "OK", "Not Found").
|
| .redirectedResponse | Array | Optional. An array of intermediate response objects encountered during redirects, if any redirects occurred. |
Dependencies
- CDP Page.navigate — the Chrome DevTools Protocol command used to initiate navigation
- CDP Network domain — used for tracking HTTP responses and redirect chains
Usage Examples
// Auto-prefixed to http://example.com
await goto('example.com');
await goto('https://example.com/login');
Custom Timeout
// Wait up to 60 seconds for slow pages
await goto('https://example.com', { navigationTimeout: 60000 });
Custom Headers
// Navigate with an authorization header
await goto('https://api.example.com', {
headers: { 'Authorization': 'Bearer token123' }
});
Inspecting the Response
const response = await goto('https://example.com');
console.log(response.url); // 'https://example.com/'
console.log(response.status.code); // 200
console.log(response.status.text); // 'OK'
// Issue navigate command without waiting for load
await goto('https://example.com', { waitForNavigation: false });
Related Pages
Implements Principle
Requires Environment
Uses Heuristic
See Also
- Getgauge_Taiko_OpenBrowser — Must be called before
gototo establish the browser connection - Getgauge_Taiko_Repl_Initialize — REPL session where
gotois commonly used interactively - Getgauge_Taiko_RunFile — Script execution mode where
gotoappears in automation scripts