import type { BrowserUserContext } from './browser.js'; import type { BrowsingContextBrowsingContext } from './browsing_context.js'; import type { EmptyResult, Extensible, JsUint } from './common.js'; export type ScriptCommand = ScriptAddPreloadScript | ScriptCallFunction | ScriptDisown | ScriptEvaluate | ScriptGetRealms | ScriptRemovePreloadScript; export type ScriptResult = ScriptAddPreloadScriptResult | ScriptCallFunctionResult | ScriptDisownResult | ScriptEvaluateResult | ScriptGetRealmsResult | ScriptRemovePreloadScriptResult; export type ScriptEvent = ScriptMessage | ScriptRealmCreated | ScriptRealmDestroyed; export type ScriptChannel = string; export interface ScriptChannelValue { type: "channel"; value: ScriptChannelProperties; } export interface ScriptChannelProperties { channel: ScriptChannel; serializationOptions?: ScriptSerializationOptions; ownership?: ScriptResultOwnership; } export type ScriptEvaluateResult = ScriptEvaluateResultSuccess | ScriptEvaluateResultException; export interface ScriptEvaluateResultSuccess { type: "success"; result: ScriptRemoteValue; realm: ScriptRealm; } export interface ScriptEvaluateResultException { type: "exception"; exceptionDetails: ScriptExceptionDetails; realm: ScriptRealm; } export interface ScriptExceptionDetails { columnNumber: JsUint; exception: ScriptRemoteValue; lineNumber: JsUint; stackTrace: ScriptStackTrace; text: string; } export type ScriptHandle = string; export type ScriptInternalId = string; export type ScriptLocalValue = ScriptRemoteReference | ScriptPrimitiveProtocolValue | ScriptChannelValue | ScriptArrayLocalValue | ScriptDateLocalValue | ScriptMapLocalValue | ScriptObjectLocalValue | ScriptRegExpLocalValue | ScriptSetLocalValue; export type ScriptListLocalValue = ScriptLocalValue[]; export interface ScriptArrayLocalValue { type: "array"; value: ScriptListLocalValue; } export interface ScriptDateLocalValue { type: "date"; value: string; } export type ScriptMappingLocalValue = (ScriptLocalValue | ScriptLocalValue)[]; export interface ScriptMapLocalValue { type: "map"; value: ScriptMappingLocalValue; } export interface ScriptObjectLocalValue { type: "object"; value: ScriptMappingLocalValue; } export interface ScriptRegExpValue { pattern: string; flags?: string; } export interface ScriptRegExpLocalValue { type: "regexp"; value: ScriptRegExpValue; } export interface ScriptSetLocalValue { type: "set"; value: ScriptListLocalValue; } export type ScriptPreloadScript = string; export type ScriptRealm = string; export type ScriptPrimitiveProtocolValue = ScriptUndefinedValue | ScriptNullValue | ScriptStringValue | ScriptNumberValue | ScriptBooleanValue | ScriptBigIntValue; export interface ScriptUndefinedValue { type: "undefined"; } export interface ScriptNullValue { type: null; } export interface ScriptStringValue { type: "string"; value: string; } export type ScriptSpecialNumber = "NaN" | "-0" | "Infinity" | "-Infinity"; export interface ScriptNumberValue { type: "number"; value: Number | ScriptSpecialNumber; } export interface ScriptBooleanValue { type: "boolean"; value: boolean; } export interface ScriptBigIntValue { type: "bigint"; value: string; } export type ScriptRealmInfo = ScriptWindowRealmInfo | ScriptDedicatedWorkerRealmInfo | ScriptSharedWorkerRealmInfo | ScriptServiceWorkerRealmInfo | ScriptWorkerRealmInfo | ScriptPaintWorkletRealmInfo | ScriptAudioWorkletRealmInfo | ScriptWorkletRealmInfo; export interface ScriptBaseRealmInfo { realm: ScriptRealm; origin: string; } export type ScriptWindowRealmInfo = ScriptBaseRealmInfo & { type: "window"; context: BrowsingContextBrowsingContext; userContext?: BrowserUserContext; sandbox?: string; }; export type ScriptDedicatedWorkerRealmInfo = ScriptBaseRealmInfo & { type: "dedicated-worker"; owners: ScriptRealm[]; }; export type ScriptSharedWorkerRealmInfo = ScriptBaseRealmInfo & { type: "shared-worker"; }; export type ScriptServiceWorkerRealmInfo = ScriptBaseRealmInfo & { type: "service-worker"; }; export type ScriptWorkerRealmInfo = ScriptBaseRealmInfo & { type: "worker"; }; export type ScriptPaintWorkletRealmInfo = ScriptBaseRealmInfo & { type: "paint-worklet"; }; export type ScriptAudioWorkletRealmInfo = ScriptBaseRealmInfo & { type: "audio-worklet"; }; export type ScriptWorkletRealmInfo = ScriptBaseRealmInfo & { type: "worklet"; }; export type ScriptRealmType = "window" | "dedicated-worker" | "shared-worker" | "service-worker" | "worker" | "paint-worklet" | "audio-worklet" | "worklet"; export type ScriptRemoteReference = ScriptSharedReference | ScriptRemoteObjectReference; export type ScriptSharedReference = Extensible & { sharedId: ScriptSharedId; handle?: ScriptHandle; }; export type ScriptRemoteObjectReference = Extensible & { handle: ScriptHandle; sharedId?: ScriptSharedId; }; export type ScriptRemoteValue = ScriptPrimitiveProtocolValue | ScriptSymbolRemoteValue | ScriptArrayRemoteValue | ScriptObjectRemoteValue | ScriptFunctionRemoteValue | ScriptRegExpRemoteValue | ScriptDateRemoteValue | ScriptMapRemoteValue | ScriptSetRemoteValue | ScriptWeakMapRemoteValue | ScriptWeakSetRemoteValue | ScriptGeneratorRemoteValue | ScriptErrorRemoteValue | ScriptProxyRemoteValue | ScriptPromiseRemoteValue | ScriptTypedArrayRemoteValue | ScriptArrayBufferRemoteValue | ScriptNodeListRemoteValue | ScriptHtmlCollectionRemoteValue | ScriptNodeRemoteValue | ScriptWindowProxyRemoteValue; export type ScriptListRemoteValue = ScriptRemoteValue[]; export type ScriptMappingRemoteValue = (ScriptRemoteValue | ScriptRemoteValue)[]; export interface ScriptSymbolRemoteValue { type: "symbol"; handle?: ScriptHandle; internalId?: ScriptInternalId; } export interface ScriptArrayRemoteValue { type: "array"; handle?: ScriptHandle; internalId?: ScriptInternalId; value?: ScriptListRemoteValue; } export interface ScriptObjectRemoteValue { type: "object"; handle?: ScriptHandle; internalId?: ScriptInternalId; value?: ScriptMappingRemoteValue; } export interface ScriptFunctionRemoteValue { type: "function"; handle?: ScriptHandle; internalId?: ScriptInternalId; } export type ScriptRegExpRemoteValue = ScriptRegExpLocalValue & { handle?: ScriptHandle; internalId?: ScriptInternalId; }; export type ScriptDateRemoteValue = ScriptDateLocalValue & { handle?: ScriptHandle; internalId?: ScriptInternalId; }; export interface ScriptMapRemoteValue { type: "map"; handle?: ScriptHandle; internalId?: ScriptInternalId; value?: ScriptMappingRemoteValue; } export interface ScriptSetRemoteValue { type: "set"; handle?: ScriptHandle; internalId?: ScriptInternalId; value?: ScriptListRemoteValue; } export interface ScriptWeakMapRemoteValue { type: "weakmap"; handle?: ScriptHandle; internalId?: ScriptInternalId; } export interface ScriptWeakSetRemoteValue { type: "weakset"; handle?: ScriptHandle; internalId?: ScriptInternalId; } export interface ScriptGeneratorRemoteValue { type: "generator"; handle?: ScriptHandle; internalId?: ScriptInternalId; } export interface ScriptErrorRemoteValue { type: "error"; handle?: ScriptHandle; internalId?: ScriptInternalId; } export interface ScriptProxyRemoteValue { type: "proxy"; handle?: ScriptHandle; internalId?: ScriptInternalId; } export interface ScriptPromiseRemoteValue { type: "promise"; handle?: ScriptHandle; internalId?: ScriptInternalId; } export interface ScriptTypedArrayRemoteValue { type: "typedarray"; handle?: ScriptHandle; internalId?: ScriptInternalId; } export interface ScriptArrayBufferRemoteValue { type: "arraybuffer"; handle?: ScriptHandle; internalId?: ScriptInternalId; } export interface ScriptNodeListRemoteValue { type: "nodelist"; handle?: ScriptHandle; internalId?: ScriptInternalId; value?: ScriptListRemoteValue; } export interface ScriptHtmlCollectionRemoteValue { type: "htmlcollection"; handle?: ScriptHandle; internalId?: ScriptInternalId; value?: ScriptListRemoteValue; } export interface ScriptNodeRemoteValue { type: "node"; sharedId?: ScriptSharedId; handle?: ScriptHandle; internalId?: ScriptInternalId; value?: ScriptNodeProperties; } export interface ScriptNodeProperties { nodeType: JsUint; childNodeCount: JsUint; attributes?: Record; children?: ScriptNodeRemoteValue[]; localName?: string; mode?: "open" | "closed"; namespaceUri?: string; nodeValue?: string; shadowRoot?: ScriptNodeRemoteValue | null; } export interface ScriptWindowProxyRemoteValue { type: "window"; value: ScriptWindowProxyProperties; handle?: ScriptHandle; internalId?: ScriptInternalId; } export interface ScriptWindowProxyProperties { context: BrowsingContextBrowsingContext; } export type ScriptResultOwnership = "root" | "none"; export interface ScriptSerializationOptions { maxDomDepth?: JsUint | null; /** * @default null */ maxObjectDepth?: JsUint | null; /** * @default 'none' */ includeShadowTree?: "none" | "open" | "all"; } export type ScriptSharedId = string; export interface ScriptStackFrame { columnNumber: JsUint; functionName: string; lineNumber: JsUint; url: string; } export interface ScriptStackTrace { callFrames: ScriptStackFrame[]; } export interface ScriptSource { realm: ScriptRealm; context?: BrowsingContextBrowsingContext; userContext?: BrowserUserContext; } export interface ScriptRealmTarget { realm: ScriptRealm; } export interface ScriptContextTarget { context: BrowsingContextBrowsingContext; sandbox?: string; } export type ScriptTarget = ScriptContextTarget | ScriptRealmTarget; export interface ScriptAddPreloadScript { method: "script.addPreloadScript"; params: ScriptAddPreloadScriptParameters; } export interface ScriptAddPreloadScriptParameters { functionDeclaration: string; arguments?: ScriptChannelValue[]; contexts?: BrowsingContextBrowsingContext[]; userContexts?: BrowserUserContext[]; sandbox?: string; } export interface ScriptAddPreloadScriptResult { script: ScriptPreloadScript; } export interface ScriptDisown { method: "script.disown"; params: ScriptDisownParameters; } export interface ScriptDisownParameters { handles: ScriptHandle[]; target: ScriptTarget; } export type ScriptDisownResult = EmptyResult; export interface ScriptCallFunction { method: "script.callFunction"; params: ScriptCallFunctionParameters; } export interface ScriptCallFunctionParameters { functionDeclaration: string; awaitPromise: boolean; target: ScriptTarget; arguments?: ScriptLocalValue[]; resultOwnership?: ScriptResultOwnership; serializationOptions?: ScriptSerializationOptions; this?: ScriptLocalValue; userActivation?: boolean; } export type ScriptCallFunctionResult = ScriptEvaluateResult; export interface ScriptEvaluate { method: "script.evaluate"; params: ScriptEvaluateParameters; } export interface ScriptEvaluateParameters { expression: string; target: ScriptTarget; awaitPromise: boolean; resultOwnership?: ScriptResultOwnership; serializationOptions?: ScriptSerializationOptions; userActivation?: boolean; } export interface ScriptGetRealms { method: "script.getRealms"; params: ScriptGetRealmsParameters; } export interface ScriptGetRealmsParameters { context?: BrowsingContextBrowsingContext; type?: ScriptRealmType; } export interface ScriptGetRealmsResult { realms: ScriptRealmInfo[]; } export interface ScriptRemovePreloadScript { method: "script.removePreloadScript"; params: ScriptRemovePreloadScriptParameters; } export interface ScriptRemovePreloadScriptParameters { script: ScriptPreloadScript; } export type ScriptRemovePreloadScriptResult = EmptyResult; export interface ScriptMessage { method: "script.message"; params: ScriptMessageParameters; } export interface ScriptMessageParameters { channel: ScriptChannel; data: ScriptRemoteValue; source: ScriptSource; } export interface ScriptRealmCreated { method: "script.realmCreated"; params: ScriptRealmInfo; } export interface ScriptRealmDestroyed { method: "script.realmDestroyed"; params: ScriptRealmDestroyedParameters; } export interface ScriptRealmDestroyedParameters { realm: ScriptRealm; } /** @deprecated Use {@link Script.create} instead — will be removed in a future major version. */ export declare function getScriptManagerInstance(driver: unknown): Promise