- Visualization — before each action, a ghost cursor animates to the target element and the element is highlighted. After the action, the highlight clears.
- Error enrichment — when a pointer action (
click,dblclick,hover) times out, additional context is captured and attached to the error.
instrumentPage()
Applies instrumentation to a Page in place and returns it typed as InstrumentedPage. The original page object is modified directly.
The Playwright
Page to instrument.See InstrumentationOptions below.
Example
installInstrumentation()
Same as instrumentPage() but returns void instead of the page. Useful when you don’t need the typed return value, or when you want to instrument a page that was passed in from elsewhere.
The Playwright
Page to patch in place.See InstrumentationOptions below.
Calling
installInstrumentation() (or instrumentPage()) on an already-instrumented page is a no-op. The check is based on the presence of page.__librettoInstrumented.instrumentContext()
Instruments all current pages in a BrowserContext and automatically instruments any pages that open in the future. Useful when connecting to an existing browser via CDP, or when your workflow opens multiple tabs.
The Playwright
BrowserContext to instrument.See InstrumentationOptions below.
Example
InstrumentationOptions
Enable ghost cursor animation and element highlight overlays. Defaults to
false.Optional logger. Navigation actions (
goto, reload, goBack, goForward) are logged at info level when a logger is provided.How long (in milliseconds) to show the element highlight before performing the action. Defaults to
350.Options for the ghost cursor overlay.
Options for the element highlight overlay.
Standalone visualization functions
You can use the ghost cursor and highlight primitives directly without going throughinstrumentPage.
Ghost cursor
ensureGhostCursor(page, options?)
Injects the ghost cursor overlay into the page if it is not already present. Also installs a page.addInitScript so the cursor reappears after navigation.
moveGhostCursor(page, target)
Animates the ghost cursor to a specific coordinate.
ghostClick(page, target)
Animates a press-and-release visual feedback on the ghost cursor at the given coordinates.
hideGhostCursor(page)
Fades the ghost cursor out.
Highlight layer
ensureHighlightLayer(page, options?)
Injects the highlight layer into the page if it is not already present.
showHighlight(page, params)
Draws a highlight rectangle over a bounding box. The highlight fades out automatically after durationMs.