donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
180 lines • 9.46 kB
TypeScript
import { ElementHandle, Locator, Page } from 'playwright';
import { FlowMetadata, State } from '../models/FlowMetadata';
import { InteractableElement } from '../models/InteractableElement';
declare global {
interface Window {
donobuNextState: string | null;
donobuGetClickableElements: () => Element[];
donobuFocusPage: () => boolean;
donobuGenerateSmartSelectors: (element: Element) => string[];
}
}
/**
* 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 readonly ACCESSIBILITY_TEST_INIT_SCRIPT;
private static readonly CLICKABLE_ELEMENTS_TRACKER_INIT_SCRIPT;
private static readonly DIALOG_PROMPT_TRACKER_INIT_SCRIPT;
private static readonly SMART_SELECTOR_GENERATOR_INIT_SCRIPT;
private static readonly PAGE_INTERACTIONS_TRACKER_INIT_SCRIPT;
private static readonly DONOBU_CONTROL_PANEL_INIT_SCRIPT;
private static readonly DONOBU_CONTROL_PANEL_ELEMENT_ID;
private static readonly DONOBU_CONTROL_PANEL_HEADLINE_ELEMENT_ID;
static readonly DONOBU_INTERACTABLE_ATTRIBUTE = "data-donobu-interactable";
static readonly DONOBU_ANNOTATION_ATTRIBUTE = "data-donobu-annotation";
/**
* Attempts to take a screenshot of the given page in PNG format, returning
* the raw byte array. If the operation fails, an empty array is returned.
* Note that if the Donobu control panel is present in the page, it will be
* excluded from the screenshot.
*/
static takePngScreenshot(page: Page): 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.
*/
static generateSelectors(element: Locator): Promise<string[]>;
/**
* Returns a JavaScript code snippet intended to run as an initialization
* script for `DonobuFlow` flows. This script helps other scripts to know
* which elements have mouse-click related event listeners attached to them
* via inspecting the {@code window.donobuGetClickableElements} element array.
*/
static clickableElementsTrackerInitScript(): string;
/**
* Returns a JavaScript code snippet intended to run as an initialization
* script for `DonobuFlow` flows. This script helps flows handle/track
* prompts/confirmations. This is done specially since these browser actions
* pause the Javascript main thread and also cause issues with running various
* Playwright actions. See `DonobuFlow.onDialog(Dialog)` for details.
*/
static dialogPromptTrackerInitScript(): string;
/**
* Returns a JavaScript code snippet intended to run as an initialization
* script for `DonobuFlow` flows. This is an in-page version of the
* `SelectorGenerator` class so that smart selectors can be generated in
* the web client. This is done so the
* {@link PlaywrightUtils.pageInteractionsTrackerInitScript()} can generate
* smart selectors on the fly and pass them to the `PageInteractionTracker`
* so the page interactions can be converted to synthetic `ToolCallResult`s.
*/
static smartSelectorGeneratorInitScript(): string;
/**
* This script is used by the `RunAccessibilityTestTool` to test the
* accessibility of a webpage. This script is injected on page load, rather
* than when running the `RunAccessibilityTestTool` because we need to bypass
* webpage Content Security Policy (CSP); this is done by injecting the
* script via `BrowserContext#addInitScript`.
*/
static accessibilityTestInitScript(): string;
static pageInteractionsTrackerInitScript(): string;
static donobuControlPanelInitScript(): string;
/**
* Creates a visual sparkle effect at the specified browser-page coordinates,
* automatically detecting if the point lies inside a same-origin iframe (and nesting deeper
* if necessary). Injects the sparkle into that frame’s document at the correct local coords.
*
* @param page - The Playwright Page object
* @param x - The x-coordinate in the top-level page coordinate space (relative to the browser window)
* @param y - The y-coordinate in the top-level page coordinate space
* @param durationMs - How long the sparkle remains (ms, default 800)
* @param emoji - The emoji to display (default '✨')
* @param size - CSS font-size for the emoji (default '40px')
*/
static createSparkleEffect(page: Page, x: number, y: number, durationMs?: number, emoji?: string, size?: string): Promise<void>;
/**
* Recursively finds the deepest same-origin Frame that covers the point (top-level coordinates).
* Returns the Frame plus the local coordinates (relative to that frame's viewport).
*
* If no same-origin child frame covers (x, y), it returns the main frame and the original coords.
*/
private static findDeepestFrameAtPoint;
static getLocatorOrItsLabel(element: Locator): Promise<Locator>;
/**
* Reads and clears the desired next state as directed by the in-flow control
* panel. Note that the control panel does not have carte blanche control, as
* we only support the control panel signaling an intent to pause and resume a
* flow.
*/
static popControlPanelNextDesiredState(page: Page): Promise<State | null>;
/**
* Hides the control panel by setting its display to 'none'. This ensures the
* panel is not visible and does not intercept mouse events.
*/
static hideControlPanel(focusedPage: Page, flowMetadata: FlowMetadata): Promise<void>;
/**
* Shows the control panel by resetting its display property. Assumes the
* original display was 'block'.
*/
static showControlPanel(focusedPage: Page, flowMetadata: FlowMetadata): Promise<void>;
/**
* Updates all control panels in the given browser context. If the provided
* headline is non-null, the headline in the control panel will be updated.
*/
static updateControlPanel(focusedPage: Page, flowMetadata: FlowMetadata, headline: string | null): Promise<void>;
/**
* Returns all elements that have the
* {@link PlaywrightUtils.DONOBU_INTERACTABLE_ATTRIBUTE} HTML attribute.
**/
static getAttributedInteractableElements(page: Page): Promise<InteractableElement[]>;
/**
* Assigns a globally unique {@link PlaywrightUtils.DONOBU_INTERACTABLE_ATTRIBUTE}
* attribute value to each visible, interactable, element in the given page.
* Any pre-existing {@link PlaywrightUtils.DONOBU_INTERACTABLE_ATTRIBUTE}
* attributes will be removed.
*/
static attributeInteractableElements(page: Page): Promise<void>;
/**
* Annotate all elements in the given page that have a
* {@link PlaywrightUtils.DONOBU_INTERACTABLE_ATTRIBUTE} HTML attribute.
*
* The annotations are placed in a shadow root to avoid site-specific CSS,
* each having a {@link PlaywrightUtils.DONOBU_ANNOTATION_ATTRIBUTE} attribute.
*/
static annotateInteractableElements(page: Page): Promise<void>;
/**
* Removes all annotations with a {@link PlaywrightUtils.DONOBU_ANNOTATION_ATTRIBUTE}
* HTML attribute in the given page, including any containers in shadow DOM.
*/
static removeDonobuAnnotations(page: Page): Promise<void>;
/**
* Removes the {@link PlaywrightUtils.DONOBU_INTERACTABLE_ATTRIBUTE} HTML
* attribute for all elements in the given page. This attribute is normally
* added by the {@link PlaywrightUtils.attributeInteractableElements(Page)}
* function.
*/
static deattributeVisibleInteractableElements(page: Page): Promise<void>;
static parseUnambiguousSelector(elementHandle: ElementHandle): Promise<string>;
/**
* Converts an HTML attribute to a JavaScript attribute. For example,
* "data-foo-bar" is turned into "fooBar". Notice the dropping of the "data-"
* prefix, and the conversion from kebab-case to camelCase.
*/
static convertToJsAttribute(htmlAttribute: string): string;
/**
* 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 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>;
private static frameFilter;
/**
* This function is injected into the page (or frame) context. It finds
* "interactable" elements, checks visibility, and sets a unique attribute.
* It returns the updated offset after labeling.
*/
private static attributeElementsInContext;
}
//# sourceMappingURL=PlaywrightUtils.d.ts.map