Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Getgauge Taiko CloseBrowser

From Leeroopedia
Knowledge Sources
Domains Browser_Automation, Resource_Management
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for gracefully terminating a browser instance and cleaning up associated resources provided by the Taiko library.

Description

The closeBrowser() function terminates the Chromium browser instance that was launched by openBrowser(). It performs a complete teardown sequence: closing the CDP WebSocket connection, sending a termination signal to the browser process, waiting for the process to exit, and removing any temporary user data directories created during the session. This ensures no orphaned browser processes or leftover files remain after automation completes.

The function takes no parameters and should be called once at the end of every automation session. It is typically placed in a finally block or test framework teardown hook to guarantee execution even when preceding steps fail.

Usage

Use closeBrowser() at the end of every Taiko automation session. Place it in afterAll/afterSuite hooks in test frameworks, or in finally blocks in standalone scripts. Always ensure it is called to prevent resource leaks, especially in CI/CD environments where orphaned processes accumulate across runs.

Code Reference

Source Location

  • Repository: Taiko
  • File: lib/taiko.js (L135-146, public API), lib/browser/launcher.js (L361-385, internal shutdown logic)

Signature

closeBrowser() -> Promise<void>

Import

const { closeBrowser } = require('taiko');

I/O Contract

Inputs

Name Type Required Description
(none) -- -- This function takes no parameters.

Outputs

Name Type Description
return Promise<void> Resolves when the browser process has been terminated and all cleanup is complete. Resolves even if the browser was already closed.

Usage Examples

Basic Closure

const { openBrowser, closeBrowser, goto } = require('taiko');

try {
    await openBrowser();
    await goto('https://example.com');
    // ... automation steps ...
} finally {
    await closeBrowser();
}

In a Test Framework Teardown

const { openBrowser, closeBrowser } = require('taiko');

beforeAll(async () => {
    await openBrowser();
});

afterAll(async () => {
    await closeBrowser();
});

In a Gauge Step Implementation

const { openBrowser, closeBrowser } = require('taiko');

afterSuite(async () => {
    await closeBrowser();
});

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment