Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright Generate Injected

From Leeroopedia

Template:Implementation Page

Overview

Generate Injected is a build utility that bundles TypeScript injected scripts into self-contained JavaScript strings that can be evaluated inside browser pages.

Description

This script uses esbuild to compile and bundle multiple TypeScript source files from the packages/injected/src directory into minified JavaScript strings. The output is written as TypeScript modules that export the bundled code as string constants, ready to be injected into browser pages via evaluateExpression.

Bundled scripts include:

  • utilityScript.ts -- utility functions for value serialization
  • injectedScript.ts -- the main injected script with selector engines
  • pollingRecorder.ts -- action recording in polling mode
  • clock.ts -- fake clock implementation
  • storageScript.ts -- storage manipulation
  • bindingsController.ts -- bindings management

Each script is bundled as an IIFE (Immediately Invoked Function Expression) with all dependencies inlined.

Usage

Run during development and before building releases to regenerate the injected script bundles.

Code Reference

Source Location

utils/generate_injected.js (150 lines)

Key Data

const injectedScripts = [
  [sourcePath, libPath, generatedPath, shouldMinify],
  // ... multiple entries
];

Execution

node utils/generate_injected.js

I/O Contract

Inputs

  • TypeScript source files from packages/injected/src/
  • esbuild configuration for bundling

Outputs

  • JavaScript bundles in packages/injected/lib/
  • TypeScript modules in packages/playwright-core/src/generated/ exporting bundled code as strings

Related Pages

Page Connections

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