Implementation:Microsoft Playwright CrDevTools
| Knowledge Sources | |
|---|---|
| Domains | Chromium, DevTools |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for intercepting and persisting Chrome DevTools preferences via runtime bindings provided by the Playwright library.
Description
The `CRDevTools` class intercepts preferences-related DevTools embedder methods through a Chrome Runtime binding (`__pw_devtools__`) and stores preferences as a JSON file at a specified path in the browser installation directory. It supports `getPreferences`, `setPreference`, `removePreference`, and `clearPreferences` methods. The class lazily loads preferences from disk on first access and batches write operations through a promise chain (`_savePromise`) to avoid concurrent file writes. It also installs a JavaScript snippet into the DevTools page that overrides the `InspectorFrontendHost` methods to route through the binding.
Usage
Use CrDevTools when Playwright opens DevTools alongside an automated browser and needs to persist user preferences (like dark mode, panel layouts) across sessions.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File: packages/playwright-core/src/server/chromium/crDevTools.ts
Signature
export class CRDevTools {
constructor(preferencesPath: string);
install(session: CRSession): void;
}
Import
import { CRDevTools } from '../server/chromium/crDevTools';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| preferencesPath | string | Yes | File system path where DevTools preferences are stored as JSON |
| session | CRSession | Yes | CDP session for the DevTools target |
Outputs
| Name | Type | Description |
|---|---|---|
| (side effect) | void | Installs runtime binding and overrides DevTools preference methods |
Usage Examples
import { CRDevTools } from '../server/chromium/crDevTools';
const devtools = new CRDevTools('/path/to/browser/devtools-preferences.json');
devtools.install(devToolsSession);
// DevTools preferences will now be persisted to the specified file