Implementation:Getgauge Taiko OpenBrowser
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, Testing |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for launching a Chromium browser instance and establishing a Chrome DevTools Protocol (CDP) connection, provided by the Taiko library.
Description
openBrowser is the foundational function in every Taiko automation script. It launches a Chromium process (either headless or headful), connects to it via the Chrome DevTools Protocol (CDP) WebSocket interface, and initializes all CDP domain handlers required for subsequent browser interactions.
Key behaviors include:
- Headless by default — the browser runs without a visible UI unless
headless: falseis specified. - Automatic port selection — when
portis0(the default), a random available port is chosen for the CDP debugging connection. - Observe mode — when
observe: true, Taiko runs in slow-motion mode with configurable delays between actions, useful for visual debugging and demonstrations. - Docker-safe flags — supports Chromium launch arguments commonly needed in containerized environments (e.g.,
--no-sandbox,--disable-dev-shm-usage). - Certificate handling — by default, certificate errors are ignored (
ignoreCertificateErrors: true), simplifying testing against self-signed or development certificates.
Usage
Call openBrowser() at the beginning of every Taiko automation script or REPL session. It must be called before any navigation or interaction functions like goto, click, or write. The browser remains open until closeBrowser() is explicitly called.
Code Reference
Source Location
- Repository: Taiko
- File:
lib/taiko.js - Lines: L90-125
Signature
module.exports.openBrowser = async (options = { headless: true }) => { ... }
Import
const { openBrowser } = require('taiko');
I/O Contract
Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| options | Object | No | { headless: true } |
Configuration object for browser launch and CDP connection. |
| options.headless | boolean | No | true |
Whether to launch Chromium in headless mode (no visible UI) or headful mode (visible browser window). |
| options.args | string[] | No | [] |
Additional Chromium command-line launch flags (e.g., --window-size=1440,900, --no-sandbox).
|
| options.host | string | No | '127.0.0.1' |
Hostname or IP address for the remote debugging connection. |
| options.port | number | No | 0 |
Remote debugging port. A value of 0 selects a random available port.
|
| options.target | string | No | — | Specific target for the chrome-remote-interface connection. |
| options.useHostName | boolean | No | false |
When true, uses the hostname instead of the IP address for the CDP connection.
|
| options.secure | boolean | No | false |
When true, uses HTTPS/WSS for the CDP frontend connection.
|
| options.ignoreCertificateErrors | boolean | No | true |
When true, ignores SSL/TLS certificate errors during navigation.
|
| options.observe | boolean | No | false |
When true, enables slow-motion observe mode for visual debugging.
|
| options.observeTime | number | No | 3000 |
Delay in milliseconds between actions when observe mode is enabled. |
| options.dumpio | boolean | No | false |
When true, dumps browser process stdout and stderr to the Node.js process.
|
Outputs
| Name | Type | Description |
|---|---|---|
| (return) | Promise<void> | Resolves when the browser is fully launched and the CDP connection is established with all domain handlers initialized. No explicit return value. |
Side Effects
- A Chromium process is spawned as a child process.
- A CDP WebSocket connection is established to the browser's debugging port.
- All CDP domain handlers (Page, Network, Runtime, DOM, etc.) are initialized and ready for use.
- Internal Taiko state is updated to track the active browser connection.
Dependencies
- chrome-remote-interface — provides the CDP WebSocket client for communicating with Chromium
- Chromium binary — the actual browser executable (bundled or system-installed)
Usage Examples
Default Headless
const { openBrowser, goto, closeBrowser } = require('taiko');
(async () => {
try {
await openBrowser();
await goto('https://example.com');
} finally {
await closeBrowser();
}
})();
Headful for Debugging
await openBrowser({ headless: false });
Custom Window Size
await openBrowser({ args: ['--window-size=1440,900'] });
Observe Mode
await openBrowser({ headless: false, observe: true, observeTime: 2000 });
Docker-Safe Configuration
await openBrowser({
args: [
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-setuid-sandbox',
'--no-first-run',
'--no-sandbox',
'--no-zygote'
]
});
Related Pages
Implements Principle
Requires Environment
- Environment:Getgauge_Taiko_Node_Runtime
- Environment:Getgauge_Taiko_Chromium_Browser
- Environment:Getgauge_Taiko_Docker_Container
Uses Heuristic
See Also
- Getgauge_Taiko_Goto — Typically called immediately after
openBrowserto navigate to a URL - Getgauge_Taiko_Repl_Initialize — REPL session where
openBrowseris commonly the first interactive command - Getgauge_Taiko_RunFile — Script execution mode that may patch
openBrowserfor observe mode