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 Repl Initialize

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

Overview

Concrete tool for initializing an interactive REPL session with all Taiko API functions injected into the global context, provided by the Taiko library.

Description

repl.initialize is the entry point for Taiko's interactive mode. It creates and configures a Node.js REPL instance that allows users to interactively execute browser automation commands. The function performs several key setup steps:

  • Injects all exported Taiko functions (e.g., openBrowser, click, write, goto) into the REPL's global context so they can be called without a module prefix.
  • Registers custom REPL commands including .code, .step, .api, .trace, .highlight, and .version.
  • Enables top-level await support via recast and @babel/parser, allowing users to write await openBrowser() directly at the prompt without wrapping in an async function.
  • Initializes persistent command history so that previously entered commands survive across REPL sessions.
  • Optionally resumes a previous recorded session by replaying commands from a session file.

Usage

Import and call initialize when launching Taiko in interactive (REPL) mode. This is typically invoked by the CLI entry point (bin/taiko.js) when no script file argument is provided. It can also be called after running a script with the --load flag to drop into an interactive session with the script's recorded commands pre-loaded.

Code Reference

Source Location

  • Repository: Taiko
  • File: lib/repl/repl.js
  • Lines: L18-55

Signature

module.exports.initialize = async (taiko, previousSessionFile, recordedSession) => { ... }

Import

const { initialize } = require('./lib/repl/repl');

I/O Contract

Inputs

Name Type Required Default Description
taiko Object Yes The main Taiko API module containing all exported functions (e.g., openBrowser, goto, click, write). Each function is injected into the REPL's global context.
previousSessionFile string No undefined Path to a previous session file. When provided, the REPL will load commands from this file to restore a prior session's state.
recordedSession boolean No undefined Whether this initialization is resuming a recorded session. When true, the REPL treats the loaded commands as a recorded session for replay.

Outputs

Name Type Description
replServer Promise<REPLServer> A fully configured Node.js REPL instance with all Taiko functions available in the global context, custom commands registered (.code, .step, .api, .trace, .highlight, .version), top-level await support enabled, and persistent command history initialized.

Side Effects

  • All Taiko API functions are injected into the REPL's global context.
  • Custom REPL commands (.code, .step, .api, .trace, .highlight, .version) are registered on the REPL server.
  • A command history file is created or appended to on disk for persistence across sessions.

Dependencies

  • Node.js repl module — provides the base REPL server implementation
  • recast + @babel/parser — used to transform user input for top-level await support
  • fs-extra — used for reading/writing session files and command history

Usage Examples

Basic Usage

const taiko = require('taiko');
const { initialize } = require('./lib/repl/repl');

// Launch an interactive REPL with all Taiko functions available
const replServer = await initialize(taiko);

Resume a Previous Session

const taiko = require('taiko');
const { initialize } = require('./lib/repl/repl');

// Resume a previously recorded session from a file
const replServer = await initialize(taiko, './previous-session.js', true);

Typical CLI Flow

// Inside bin/taiko.js, when no script file is provided:
const taiko = require('./lib/taiko');
const { initialize } = require('./lib/repl/repl');

(async () => {
  const server = await initialize(taiko);
  server.on('exit', () => {
    process.exit();
  });
})();

Related Pages

Implements Principle

Requires Environment

See Also

Page Connections

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