UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

76 lines 3.84 kB
import type { BrowserContext, Locator, Page, PageScreenshotOptions } from 'playwright'; /** * Miscellaneous utility functions for working with the Playwright SDK. If you are looking to * instantiate a Playwright instance, see PlaywrightSetup instead. */ export declare class PlaywrightUtils { private static _blankJpeg; private static _blankPng; private static get BLANK_JPEG(); private static get BLANK_PNG(); /** * Takes a screenshot of the given page, returning the raw byte array. * * Playwright's native `page.screenshot()` hangs when the renderer is * blocked (synchronous JS, mid-navigation, font loading, etc.). To avoid * this, two capture strategies race in parallel against a shared timeout: * * 1. **Playwright native** — highest quality, wins when the renderer is * responsive. * 2. **CDP `Page.captureScreenshot`** — captures from the browser's * compositor layer, which remains available even when the renderer is * blocked. Chromium-only; silently drops out on Firefox/WebKit. * * If neither strategy resolves within `timeoutMs`, a static fallback image * ("No screenshot available.") is returned from the assets directory. This * makes the method effectively infallible — it always returns a `Buffer` * unless the page is closed, in which case {@link PageClosedException} is * thrown. */ static takeViewportScreenshot(page: Page, options?: PageScreenshotOptions): Promise<Buffer>; /** * Generate valid selectors for the given element. The generated selectors are * in a priority order based on their ability to identify the given element. * For example, an unambiguous selector that matches the element exactly are * first in the list, and weaker selectors that match multiple elements are * last. * * NOTE: Using Locator['evaluate'] as the type for 'evaluate' as it is * conveniently compatible with Element['evaluate'], and we want to be * able to generate selectors when passed either a Locator or Element. */ static generateSelectors(element: { evaluate: Locator['evaluate']; }): Promise<string[]>; /** * Sets up the given browser context so that it can be minimally used by the * rest of Donobu. This involves registering critical page initialization * scripts. */ static setupBasicBrowserContext(browserContext: BrowserContext): Promise<void>; /** * Returned true IFF the given error is a Playwright error regarding page closing, * of if the given error is an instance of {@link PageClosedException}. */ static isPageClosedError(error: any): boolean; static ensurePlaywrightInstallation(): Promise<void>; static ensureChromiumInstallation(): Promise<void>; static ensureFirefoxInstallation(): Promise<void>; static ensureWebkitInstallation(): Promise<void>; static isBrowserInstalled(browserType: 'chromium' | 'firefox' | 'webkit'): Promise<boolean>; private static readonly _browserInstallPromises; static ensureBrowserReady(browserType: 'chromium' | 'firefox' | 'webkit'): Promise<void>; static runPlaywrightCli(args: string[]): Promise<void>; /** * Attempts to wait until the currently focused page is stable. If the page * never stabilizes, it just returns after timing out. If any error occurs, * it is logged and ignored. If page is null, this function has no effect. */ static waitForPageStability(page: Page | null): Promise<void>; /** * Returns true IFF if the given selector is an xpath-based selector. */ static isXpathSelector(selector: string): boolean; static normalizeSelector(selector: string): string; } //# sourceMappingURL=PlaywrightUtils.d.ts.map