import type { BrowserClientWindow, BrowserUserContext } from './browser.js'; import type { EmptyResult, JsInt, JsUint } from './common.js'; import type { ScriptNodeRemoteValue, ScriptSerializationOptions, ScriptSharedReference } from './script.js'; import type { SessionUserPromptHandlerType } from './session.js'; export type BrowsingContextCommand = BrowsingContextActivate | BrowsingContextCaptureScreenshot | BrowsingContextClose | BrowsingContextCreate | BrowsingContextGetTree | BrowsingContextHandleUserPrompt | BrowsingContextLocateNodes | BrowsingContextNavigate | BrowsingContextPrint | BrowsingContextReload | BrowsingContextSetBypassCsp | BrowsingContextSetViewport | BrowsingContextTraverseHistory; export type BrowsingContextResult = BrowsingContextActivateResult | BrowsingContextCaptureScreenshotResult | BrowsingContextCloseResult | BrowsingContextCreateResult | BrowsingContextGetTreeResult | BrowsingContextHandleUserPromptResult | BrowsingContextLocateNodesResult | BrowsingContextNavigateResult | BrowsingContextPrintResult | BrowsingContextReloadResult | BrowsingContextSetBypassCspResult | BrowsingContextSetViewportResult | BrowsingContextTraverseHistoryResult; export type BrowsingContextEvent = BrowsingContextContextCreated | BrowsingContextContextDestroyed | BrowsingContextDomContentLoaded | BrowsingContextDownloadEnd | BrowsingContextDownloadWillBegin | BrowsingContextFragmentNavigated | BrowsingContextHistoryUpdated | BrowsingContextLoad | BrowsingContextNavigationAborted | BrowsingContextNavigationCommitted | BrowsingContextNavigationFailed | BrowsingContextNavigationStarted | BrowsingContextUserPromptClosed | BrowsingContextUserPromptOpened; export type BrowsingContextBrowsingContext = string; export type BrowsingContextInfoList = BrowsingContextInfo[]; export interface BrowsingContextInfo { children: BrowsingContextInfoList | null; clientWindow: BrowserClientWindow; context: BrowsingContextBrowsingContext; originalOpener: BrowsingContextBrowsingContext | null; url: string; userContext: BrowserUserContext; parent?: BrowsingContextBrowsingContext | null; } export type BrowsingContextLocator = BrowsingContextAccessibilityLocator | BrowsingContextCssLocator | BrowsingContextContextLocator | BrowsingContextInnerTextLocator | BrowsingContextXPathLocator; export interface BrowsingContextAccessibilityLocator { type: "accessibility"; value: { name?: string; role?: string; }; } export interface BrowsingContextCssLocator { type: "css"; value: string; } export interface BrowsingContextContextLocator { type: "context"; value: { context: BrowsingContextBrowsingContext; }; } export interface BrowsingContextInnerTextLocator { type: "innerText"; value: string; ignoreCase?: boolean; matchType?: "full" | "partial"; maxDepth?: JsUint; } export interface BrowsingContextXPathLocator { type: "xpath"; value: string; } export type BrowsingContextNavigation = string; export interface BrowsingContextBaseNavigationInfo { context: BrowsingContextBrowsingContext; navigation: BrowsingContextNavigation | null; timestamp: JsUint; url: string; userContext?: BrowserUserContext; } export type BrowsingContextNavigationInfo = BrowsingContextBaseNavigationInfo; export type BrowsingContextReadinessState = "none" | "interactive" | "complete"; export type BrowsingContextUserPromptType = "alert" | "beforeunload" | "confirm" | "prompt"; export interface BrowsingContextActivate { method: "browsingContext.activate"; params: BrowsingContextActivateParameters; } export interface BrowsingContextActivateParameters { context: BrowsingContextBrowsingContext; } export type BrowsingContextActivateResult = EmptyResult; export interface BrowsingContextCaptureScreenshot { method: "browsingContext.captureScreenshot"; params: BrowsingContextCaptureScreenshotParameters; } export interface BrowsingContextCaptureScreenshotParameters { context: BrowsingContextBrowsingContext; /** * @default 'viewport' */ origin?: "viewport" | "document"; format?: BrowsingContextImageFormat; clip?: BrowsingContextClipRectangle; } export interface BrowsingContextImageFormat { type: string; quality?: number; } export type BrowsingContextClipRectangle = BrowsingContextBoxClipRectangle | BrowsingContextElementClipRectangle; export interface BrowsingContextElementClipRectangle { type: "element"; element: ScriptSharedReference; } export interface BrowsingContextBoxClipRectangle { type: "box"; x: number; y: number; width: number; height: number; } export interface BrowsingContextCaptureScreenshotResult { data: string; } export interface BrowsingContextClose { method: "browsingContext.close"; params: BrowsingContextCloseParameters; } export interface BrowsingContextCloseParameters { context: BrowsingContextBrowsingContext; promptUnload?: boolean; } export type BrowsingContextCloseResult = EmptyResult; export interface BrowsingContextCreate { method: "browsingContext.create"; params: BrowsingContextCreateParameters; } export type BrowsingContextCreateType = "tab" | "window"; export interface BrowsingContextCreateParameters { type: BrowsingContextCreateType; referenceContext?: BrowsingContextBrowsingContext; background?: boolean; userContext?: BrowserUserContext; } export interface BrowsingContextCreateResult { context: BrowsingContextBrowsingContext; userContext?: BrowserUserContext; } export interface BrowsingContextGetTree { method: "browsingContext.getTree"; params: BrowsingContextGetTreeParameters; } export interface BrowsingContextGetTreeParameters { maxDepth?: JsUint; root?: BrowsingContextBrowsingContext; } export interface BrowsingContextGetTreeResult { contexts: BrowsingContextInfoList; } export interface BrowsingContextHandleUserPrompt { method: "browsingContext.handleUserPrompt"; params: BrowsingContextHandleUserPromptParameters; } export interface BrowsingContextHandleUserPromptParameters { context: BrowsingContextBrowsingContext; accept?: boolean; userText?: string; } export type BrowsingContextHandleUserPromptResult = EmptyResult; export interface BrowsingContextLocateNodes { method: "browsingContext.locateNodes"; params: BrowsingContextLocateNodesParameters; } export interface BrowsingContextLocateNodesParameters { context: BrowsingContextBrowsingContext; locator: BrowsingContextLocator; maxNodeCount?: JsUint; serializationOptions?: ScriptSerializationOptions; startNodes?: ScriptSharedReference[]; } export interface BrowsingContextLocateNodesResult { nodes: ScriptNodeRemoteValue[]; } export interface BrowsingContextNavigate { method: "browsingContext.navigate"; params: BrowsingContextNavigateParameters; } export interface BrowsingContextNavigateParameters { context: BrowsingContextBrowsingContext; url: string; wait?: BrowsingContextReadinessState; } export interface BrowsingContextNavigateResult { navigation: BrowsingContextNavigation | null; url: string; } export interface BrowsingContextPrint { method: "browsingContext.print"; params: BrowsingContextPrintParameters; } export interface BrowsingContextPrintParameters { context: BrowsingContextBrowsingContext; background?: boolean; margin?: BrowsingContextPrintMarginParameters; /** * @default 'portrait' */ orientation?: "portrait" | "landscape"; page?: BrowsingContextPrintPageParameters; pageRanges?: (JsUint | string)[]; /** * @default 1 */ scale?: number; /** * @default true */ shrinkToFit?: boolean; } export interface BrowsingContextPrintMarginParameters { /** * @default 1 */ bottom?: number; /** * @default 1 */ left?: number; /** * @default 1 */ right?: number; /** * @default 1 */ top?: number; } export interface BrowsingContextPrintPageParameters { /** * @default 27.94 */ height?: number; /** * @default 21.59 */ width?: number; } export interface BrowsingContextPrintResult { data: string; } export interface BrowsingContextReload { method: "browsingContext.reload"; params: BrowsingContextReloadParameters; } export interface BrowsingContextReloadParameters { context: BrowsingContextBrowsingContext; ignoreCache?: boolean; wait?: BrowsingContextReadinessState; } export type BrowsingContextReloadResult = BrowsingContextNavigateResult; export interface BrowsingContextSetBypassCsp { method: "browsingContext.setBypassCSP"; params: BrowsingContextSetBypassCspParameters; } export interface BrowsingContextSetBypassCspParameters { bypass: true | null; contexts?: BrowsingContextBrowsingContext[]; userContexts?: BrowserUserContext[]; } export type BrowsingContextSetBypassCspResult = EmptyResult; export interface BrowsingContextSetViewport { method: "browsingContext.setViewport"; params: BrowsingContextSetViewportParameters; } export interface BrowsingContextSetViewportParameters { context?: BrowsingContextBrowsingContext; viewport?: BrowsingContextViewport | null; devicePixelRatio?: number | null; userContexts?: BrowserUserContext[]; } export interface BrowsingContextViewport { width: JsUint; height: JsUint; } export type BrowsingContextSetViewportResult = EmptyResult; export interface BrowsingContextTraverseHistory { method: "browsingContext.traverseHistory"; params: BrowsingContextTraverseHistoryParameters; } export interface BrowsingContextTraverseHistoryParameters { context: BrowsingContextBrowsingContext; delta: JsInt; } export type BrowsingContextTraverseHistoryResult = EmptyResult; export interface BrowsingContextContextCreated { method: "browsingContext.contextCreated"; params: BrowsingContextInfo; } export interface BrowsingContextContextDestroyed { method: "browsingContext.contextDestroyed"; params: BrowsingContextInfo; } export interface BrowsingContextNavigationStarted { method: "browsingContext.navigationStarted"; params: BrowsingContextNavigationInfo; } export interface BrowsingContextFragmentNavigated { method: "browsingContext.fragmentNavigated"; params: BrowsingContextNavigationInfo; } export interface BrowsingContextHistoryUpdated { method: "browsingContext.historyUpdated"; params: BrowsingContextHistoryUpdatedParameters; } export interface BrowsingContextHistoryUpdatedParameters { context: BrowsingContextBrowsingContext; timestamp: JsUint; url: string; userContext?: BrowserUserContext; } export interface BrowsingContextDomContentLoaded { method: "browsingContext.domContentLoaded"; params: BrowsingContextNavigationInfo; } export interface BrowsingContextLoad { method: "browsingContext.load"; params: BrowsingContextNavigationInfo; } export interface BrowsingContextDownloadWillBegin { method: "browsingContext.downloadWillBegin"; params: BrowsingContextDownloadWillBeginParams; } export type BrowsingContextDownloadWillBeginParams = BrowsingContextBaseNavigationInfo & { suggestedFilename: string; }; export interface BrowsingContextDownloadEnd { method: "browsingContext.downloadEnd"; params: BrowsingContextDownloadEndParams; } export type BrowsingContextDownloadEndParams = (BrowsingContextDownloadCanceledParams | BrowsingContextDownloadCompleteParams); export type BrowsingContextDownloadCanceledParams = BrowsingContextBaseNavigationInfo & { status: "canceled"; }; export type BrowsingContextDownloadCompleteParams = BrowsingContextBaseNavigationInfo & { status: "complete"; filepath: string | null; }; export interface BrowsingContextNavigationAborted { method: "browsingContext.navigationAborted"; params: BrowsingContextNavigationInfo; } export interface BrowsingContextNavigationCommitted { method: "browsingContext.navigationCommitted"; params: BrowsingContextNavigationInfo; } export interface BrowsingContextNavigationFailed { method: "browsingContext.navigationFailed"; params: BrowsingContextNavigationInfo; } export interface BrowsingContextUserPromptClosed { method: "browsingContext.userPromptClosed"; params: BrowsingContextUserPromptClosedParameters; } export interface BrowsingContextUserPromptClosedParameters { context: BrowsingContextBrowsingContext; accepted: boolean; type: BrowsingContextUserPromptType; userContext?: BrowserUserContext; userText?: string; } export interface BrowsingContextUserPromptOpened { method: "browsingContext.userPromptOpened"; params: BrowsingContextUserPromptOpenedParameters; } export interface BrowsingContextUserPromptOpenedParameters { context: BrowsingContextBrowsingContext; handler: SessionUserPromptHandlerType; message: string; type: BrowsingContextUserPromptType; userContext?: BrowserUserContext; defaultValue?: string; } /** @deprecated Use {@link BrowsingContext.create} instead — will be removed in a future major version. */ export declare function getBrowsingContextInstance(driver: unknown): Promise; export declare class BrowsingContext { private readonly bidi; private constructor(); static create(driver: unknown): Promise; activate(params: BrowsingContextActivateParameters): Promise; captureScreenshot(params: BrowsingContextCaptureScreenshotParameters): Promise; close(params: BrowsingContextCloseParameters): Promise; create(params: BrowsingContextCreateParameters): Promise; getTree(params: BrowsingContextGetTreeParameters): Promise; handleUserPrompt(params: BrowsingContextHandleUserPromptParameters): Promise; locateNodes(params: BrowsingContextLocateNodesParameters): Promise; navigate(params: BrowsingContextNavigateParameters): Promise; print(params: BrowsingContextPrintParameters): Promise; reload(params: BrowsingContextReloadParameters): Promise; setBypassCSP(params: BrowsingContextSetBypassCspParameters): Promise; setViewport(params: BrowsingContextSetViewportParameters): Promise; traverseHistory(params: BrowsingContextTraverseHistoryParameters): Promise; onContextCreated(callback: (params: BrowsingContextInfo) => void): Promise; onContextDestroyed(callback: (params: BrowsingContextInfo) => void): Promise; onDomContentLoaded(callback: (params: BrowsingContextNavigationInfo) => void): Promise; onDownloadEnd(callback: (params: BrowsingContextDownloadEndParams) => void): Promise; onDownloadWillBegin(callback: (params: BrowsingContextDownloadWillBeginParams) => void): Promise; onFragmentNavigated(callback: (params: BrowsingContextNavigationInfo) => void): Promise; onHistoryUpdated(callback: (params: BrowsingContextHistoryUpdatedParameters) => void): Promise; onLoad(callback: (params: BrowsingContextNavigationInfo) => void): Promise; onNavigationAborted(callback: (params: BrowsingContextNavigationInfo) => void): Promise; onNavigationCommitted(callback: (params: BrowsingContextNavigationInfo) => void): Promise; onNavigationFailed(callback: (params: BrowsingContextNavigationInfo) => void): Promise; onNavigationStarted(callback: (params: BrowsingContextNavigationInfo) => void): Promise; onUserPromptClosed(callback: (params: BrowsingContextUserPromptClosedParameters) => void): Promise; onUserPromptOpened(callback: (params: BrowsingContextUserPromptOpenedParameters) => void): Promise; back(context: BrowsingContextBrowsingContext): Promise; forward(context: BrowsingContextBrowsingContext): Promise; getTopLevelContexts(): Promise; printPage(params: BrowsingContextPrintParameters): Promise; }