// ABI Hash: 7799daab4b4534c95423f9fb381c3a836fe39c4fc06068a3499564d992e02135 import Foundation /// Actor managing WebSocket communication and URLSession tasks for Chrome DevTools Protocol. public actor BrowserCDPEngine { public let host: String = "" public let port: Int = 0 private let session: URLSession = .shared private var webSocketTask: URLSessionWebSocketTask? = nil private var requestCounter: Int = 1 private var pendingRequests: [Int: CheckedContinuation] = [:] private var listenTask: Task? = nil /// Target IDs created and owned by this actor instance. public private(set) var ownedTargetIDs: Set = [] /// Returns the target IDs owned by this session as an array. public var ownedTargets: [String] { fatalError() } /// Returns the target IDs owned by this session as a set. public func getOwnedTargetIDs() -> Set { fatalError() } public init(host: String = "127.0.0.1", port: Int = 9222, session: URLSession = .shared) { fatalError() } deinit { fatalError() } /// Performs a GET request against http://:/json to discover available CDP targets. /// /// - Returns: An array of `CDPTarget` models representing all inspectable browser targets (pages, workers, contexts). /// - Throws: `BrowserCDPError.invalidURL` if the endpoint URL is invalid, or `BrowserCDPError.invalidResponsePayload` if the HTTP response fails or cannot be decoded. public func discoverTargets() async throws -> [CDPTarget] { fatalError() } /// Finds an existing matching browser window/target or creates a new window if none exists. /// /// Performs target matching across available targets by comparing target URLs (matching protocol, host, port, path, and query). /// If an existing window or page matches, it reuses the target, claims ownership, brings the target to the physical foreground /// by calling `Target.activateTarget`, and safely reloads the page via `Page.reload` if `reloadIfExisting` is `true`. /// If no matching target is found, a new browser window is created via `createWindow(url:)` and focused. /// /// - Parameters: /// - url: The target URL string to match or navigate to. /// - reloadIfExisting: When `true`, connects to the existing target's WebSocket endpoint and issues `Page.reload`. Defaults to `true`. /// - Returns: The discovered or newly created `CDPTarget` instance. /// - Throws: `BrowserCDPError` if target discovery or window creation fails. @discardableResult public func findOrCreateWindow(url: String, reloadIfExisting: Bool = true) async throws -> CDPTarget { fatalError() } private func urlsMatch(_ lhs: String, _ rhs: String) -> Bool { fatalError() } /// Activates a target to bring its window and tab to the foreground. /// /// Sends `Target.activateTarget` via CDP to focus the target window and bring its tab to the foreground. /// /// - Parameter targetId: The identifier of the target to bring to the foreground. /// - Throws: `BrowserCDPError` if the command fails or the engine is disconnected. public func activateTarget(targetId: String) async throws { fatalError() } /// Creates a new browser window target, records its ownership, and returns its metadata. /// /// Sends `Target.createTarget` with `newWindow: true`, registers the target in `ownedTargetIDs`, /// activates the target window to bring it to the foreground, and queries `discoverTargets()` to return full target metadata. /// /// - Parameters: /// - url: The initial URL to navigate to in the new window. Defaults to `"about:blank"`. /// - browserContextId: Optional isolated browser context identifier to create the window within. /// - Returns: The `CDPTarget` instance representing the newly created window. /// - Throws: `BrowserCDPError` if creation fails or the returned response is missing `targetId`. @discardableResult public func createWindow(url: String = "about:blank", browserContextId: String? = nil) async throws -> CDPTarget { fatalError() } /// Creates a new browser tab target, records its ownership, and returns its metadata. /// /// Sends `Target.createTarget` with `newWindow: false`, registers the target in `ownedTargetIDs`, /// activates the tab to bring it to the foreground, and queries `discoverTargets()` to return full target metadata. /// /// - Parameters: /// - url: The initial URL to navigate to in the new tab. Defaults to `"about:blank"`. /// - browserContextId: Optional isolated browser context identifier to create the tab within. /// - Returns: The `CDPTarget` instance representing the newly created tab. /// - Throws: `BrowserCDPError` if creation fails or the returned response is missing `targetId`. @discardableResult public func createTab(url: String = "about:blank", browserContextId: String? = nil) async throws -> CDPTarget { fatalError() } /// Closes an owned target. /// /// Sends `Target.closeTarget` for the specified target and removes it from the owned target registry. /// /// - Parameter targetId: The identifier of the target to close. /// - Throws: `BrowserCDPError.unownedTarget` if the target was not created by this session, or `BrowserCDPError.commandFailed` if closing fails. public func closeTarget(targetId: String) async throws { fatalError() } /// Closes all targets owned by this session and clears the ownership tracking set. /// /// Iterates through `ownedTargetIDs`, dispatching `Target.closeTarget` for each target, and clears the ownership registry. /// /// - Throws: `BrowserCDPError` if communication fails during closure. public func closeOwnedTargets() async throws { fatalError() } /// Sweeps and closes active targets owned by this session, preserving the specified target ID. /// /// Discovers active targets and closes any owned target whose ID does not match `keepingTargetID`. /// /// - Parameter keepingTargetID: The target ID to keep active while closing other owned targets. /// - Throws: `BrowserCDPError` if target discovery fails. public func closeUnusedOwnedTabs(keepingTargetID: String) async throws { fatalError() } /// Sweeps and closes active targets owned by this session, preserving the specified target ID (alias). /// /// - Parameter keepingTargetId: The target ID to keep active while closing other owned targets. /// - Throws: `BrowserCDPError` if target discovery fails. public func closeUnusedOwnedTabs(keepingTargetId: String) async throws { fatalError() } /// Creates an isolated browser context partition and returns the context ID. /// /// Issues `Target.createBrowserContext` to create an isolated browsing context (similar to an incognito profile). /// /// - Returns: The unique string identifier for the newly created browser context (`browserContextId`). /// - Throws: `BrowserCDPError.browserContextFailed` if creation fails or the context ID is missing. @discardableResult public func createBrowserContext() async throws -> String { fatalError() } /// Disposes of an isolated browser context partition. /// /// Issues `Target.disposeBrowserContext` to clean up and destroy the specified browser context partition. /// /// - Parameter contextId: The unique identifier of the browser context to dispose. /// - Throws: `BrowserCDPError` if the disposal command fails. public func disposeBrowserContext(contextId: String) async throws { fatalError() } /// Disposes of an isolated browser context partition (alias). /// /// - Parameter browserContextId: The unique identifier of the browser context to dispose. /// - Throws: `BrowserCDPError` if the disposal command fails. public func disposeBrowserContext(browserContextId: String) async throws { fatalError() } /// Connects to a browser instance using its HTTP debug endpoint, resolving the WebSocket debugger URL. /// /// Passing an HTTP or HTTPS URL causes the engine to first query the browser's `/json/version` HTTP endpoint /// to resolve the `webSocketDebuggerUrl` string before establishing the underlying `URLSessionWebSocketTask` connection. /// /// - Parameter url: The base HTTP/HTTPS URL of the remote debugging interface (defaults to `http://127.0.0.1:9222`). /// - Throws: `BrowserCDPError.invalidURL` or `BrowserCDPError.invalidResponsePayload` if endpoint discovery fails. public func connectToBrowser(at url: URL = URL(string: "http://127.0.0.1:9222")!) async throws { fatalError() } /// Connects to a browser instance using its HTTP debug endpoint string, resolving the WebSocket debugger URL. /// /// Passing an HTTP or HTTPS URL string causes the engine to query the browser's `/json/version` HTTP endpoint /// to resolve the active `webSocketDebuggerUrl` string before initiating the WebSocket session. /// /// - Parameter urlString: The base HTTP/HTTPS URL string of the remote debugging interface (e.g., `"http://127.0.0.1:9222"`). /// - Throws: `BrowserCDPError.invalidURL` if the string cannot be parsed, or `BrowserCDPError.invalidResponsePayload` if resolution fails. public func connectToBrowser(at urlString: String) async throws { fatalError() } /// Connects directly to a CDP WebSocket target URL string. /// /// - Parameter targetWebSocketUrl: The WebSocket URL string (e.g., `"ws://127.0.0.1:9222/devtools/page/..."`). /// - Throws: `BrowserCDPError.invalidURL` if the URL string is invalid, or connection errors during handshake. public func connect(targetWebSocketUrl: String) async throws { fatalError() } /// Connects to a CDP target URL, resolving HTTP/HTTPS URLs to their WebSocket debugger URL. /// /// When passed an HTTP or HTTPS scheme, this method queries the `/json/version` endpoint to resolve /// the browser's `webSocketDebuggerUrl` before opening the WebSocket task. For `ws` or `wss` URLs, /// it connects directly to the specified endpoint. /// /// - Parameter url: The HTTP or WebSocket URL to connect to. /// - Throws: `BrowserCDPError.invalidURL` or `BrowserCDPError.invalidResponsePayload` if resolution or handshake fails. public func connect(to url: URL) async throws { fatalError() } /// Cleanly disconnects and cancels the active WebSocket task. /// /// Cancels background listener tasks, closes the WebSocket connection with `.normalClosure`, /// and terminates all in-flight pending request continuations with `BrowserCDPError.disconnected`. public func disconnect() { fatalError() } private func startListening(task: URLSessionWebSocketTask) { fatalError() } private func handleIncomingMessage(_ message: URLSessionWebSocketTask.Message) { fatalError() } private func handleWebSocketFailure(error: Error) { fatalError() } /// Sends a raw JSON-RPC command over the WebSocket connection and awaits the response matching the request ID. /// /// Encodes the command as a JSON-RPC 2.0 payload with a unique auto-incremented integer ID. /// Awaits the asynchronous response matching that ID, verifies there is no error in the payload, and returns /// the unwrapped `result` dictionary payload matching the Chrome DevTools Protocol specification. /// /// - Parameters: /// - method: The CDP domain method name (e.g., `"Runtime.evaluate"`, `"Page.reload"`, `"Target.createTarget"`). /// - params: Optional dictionary of parameters conforming to the CDP method schema. /// - Returns: A dictionary containing the unwrapped `result` payload conforming to the CDP specification (e.g. `["targetId": "..."]` or `["result": ...]`). /// - Throws: `BrowserCDPError.disconnected` if the WebSocket is not open, or `BrowserCDPError.commandFailed` if serialization fails or CDP reports an error. @discardableResult public func sendCommand(method: String, params: [String: Any]? = nil) async throws -> [String: Any] { fatalError() } private func failRequest(id: Int, error: Error) { fatalError() } /// Evaluates a JavaScript expression on the current page via Chrome DevTools Protocol `Runtime.evaluate`. /// /// Dispatches a `Runtime.evaluate` command with `returnByValue: true` over the active WebSocket connection. /// Returns the standard CDP dictionary envelope containing the `result` RemoteObject payload, which typically /// contains `type`, `value`, or `description` fields (e.g., `["result": ["type": "string", "value": "..."]]`). /// /// - Parameter expression: The JavaScript expression or statement to evaluate in the page execution context. /// - Returns: The standard CDP dictionary envelope containing the `result` object (e.g., `["result": ["type": "string", "value": "..."]]`). /// - Throws: `BrowserCDPError.disconnected` if disconnected, or `BrowserCDPError.commandFailed` if evaluation fails or throws an exception. @discardableResult public func evaluateJavaScript(_ expression: String) async throws -> [String: Any] { fatalError() } /// Simulates physical input via Chrome DevTools Protocol `Input.dispatchMouseEvent`. /// /// Sends a low-level mouse event (such as `"mousePressed"`, `"mouseReleased"`, or `"mouseMoved"`) /// to the page coordinates specified by `(x, y)`. /// /// - Parameters: /// - type: The mouse event type (e.g., `"mousePressed"`, `"mouseReleased"`, `"mouseMoved"`). /// - x: The X coordinate in viewport CSS pixels. /// - y: The Y coordinate in viewport CSS pixels. /// - button: The mouse button pressed (e.g., `"left"`, `"middle"`, `"right"`, `"none"`). Defaults to `"left"`. /// - clickCount: Number of sequential clicks (e.g., 1 for single click, 2 for double click). Defaults to 1. /// - Returns: The command completion dictionary payload returned by the CDP endpoint (empty dictionary `[:]` on success per CDP spec). /// - Throws: `BrowserCDPError.disconnected` if disconnected, or `BrowserCDPError.commandFailed` if the command fails. @discardableResult public func dispatchMouseEvent( type: String, x: Double, y: Double, button: String = "left", clickCount: Int = 1 ) async throws -> [String: Any] { fatalError() } /// Fires mousePressed and mouseReleased sequentially at coordinates (x, y). /// /// Simulates a complete mouse click by dispatching `mousePressed` followed by `mouseReleased` at the specified coordinates. /// /// - Parameters: /// - x: The X coordinate in viewport CSS pixels. /// - y: The Y coordinate in viewport CSS pixels. /// - button: The mouse button to click (e.g. `"left"`). Defaults to `"left"`. /// - Throws: `BrowserCDPError` if the underlying `dispatchMouseEvent` commands fail. public func click(x: Double, y: Double, button: String = "left") async throws { fatalError() } /// Populates text fields and triggers synthetic input/change events. /// /// Injects text into the active element or first available input, textarea, or contenteditable element, /// and fires synthetic `input` and `change` events so modern reactive web frameworks detect the change. /// /// - Parameter prompt: The text prompt or value to insert into the form field. /// - Throws: `BrowserCDPError` if script evaluation fails. public func injectPrompt(_ prompt: String) async throws { fatalError() } /// Finds and clicks the generate button on the page. /// /// Evaluates a JavaScript snippet searching for buttons or submit inputs with labels matching common generation keywords /// (e.g., "generate", "create", "submit") and triggers a native click event. /// /// - Throws: `BrowserCDPError` if script evaluation fails. public func clickGenerateButton() async throws { fatalError() } /// Polls the page DOM via JS evaluation until rendered image URLs appear or timeout is exceeded. /// /// Continuously inspects `` elements in the DOM matching master/rendered image heuristics /// until a valid source URL is located or `timeoutSeconds` expires. /// /// - Parameter timeoutSeconds: Maximum time in seconds to wait for the image URL to appear. Defaults to 30.0. /// - Returns: The resolved absolute or data URL string of the rendered master image. /// - Throws: `BrowserCDPError.commandFailed` if timed out or if evaluation fails. public func pollForMasterImageURL(timeoutSeconds: TimeInterval = 30.0) async throws -> String { fatalError() } /// Downloads an asset from a URL, automatically stripping query parameters, and writes data atomically to destination POSIX path. /// /// Strips query parameters from the asset URL, downloads the binary payload via `URLSession`, /// verifies a 2xx HTTP response status, creates intermediate parent directories if needed, and writes the data atomically to disk. /// /// - Parameters: /// - urlString: The remote asset URL string to download. /// - destinationPath: The absolute POSIX filesystem path where the downloaded file should be written. /// - Returns: The local `URL` pointing to the downloaded file on disk. /// - Throws: `BrowserCDPError.invalidURL` if the URL is invalid, or `BrowserCDPError.assetDownloadFailed` if downloading or writing fails. @discardableResult public func downloadAsset(from urlString: String, to destinationPath: String) async throws -> URL { fatalError() } } @_exported import Foundation @_exported import StreamlineFoundation internal import SwiftSoup public enum BrowserCDPError: Error, LocalizedError, Sendable { case invalidURL(String) case disconnected case commandFailed(message: String) case invalidResponsePayload case assetDownloadFailed(message: String) case unownedTarget(id: String) case browserContextFailed(message: String) public var errorDescription: String? { fatalError() } } public struct CDPTarget: Codable, Identifiable, Sendable { public let id: String public let title: String public let type: String public let url: String public let webSocketDebuggerUrl: String? public init( id: String, title: String, type: String, url: String, webSocketDebuggerUrl: String? = nil ) { fatalError() } } public struct CDPVersion: Codable, Sendable { public let browser: String? public let protocolVersion: String? public let userAgent: String? public let v8Version: String? public let webKitVersion: String? public let webSocketDebuggerUrl: String? enum CodingKeys: String, CodingKey { case browser = "Browser" case protocolVersion = "Protocol-Version" case userAgent = "User-Agent" case v8Version = "V8-Version" case webKitVersion = "WebKit-Version" case webSocketDebuggerUrl } public init( browser: String? = nil, protocolVersion: String? = nil, userAgent: String? = nil, v8Version: String? = nil, webKitVersion: String? = nil, webSocketDebuggerUrl: String? = nil ) { fatalError() } } public struct DOMElement: Sendable, Identifiable, Hashable { public let id: UUID public let tagName: String public let text: String public let attributes: [String: String] public let outerHTML: String public init(id: UUID = UUID(), tagName: String, text: String, attributes: [String: String], outerHTML: String) { fatalError() } public func attr(_ name: String) -> String? { fatalError() } } public enum DOMParserError: Error, LocalizedError, Sendable { case invalidOrEmptyHTML case selectorQueryFailed(message: String) case unhandledParsingError(message: String) public var errorDescription: String? { fatalError() } } public enum DOMParser: Sendable { public static func parseText(_ html: String) -> String { fatalError() } public static func select(_ selector: String, html: String) throws -> [DOMElement] { fatalError() } private static func attributes(in outerHTML: String) -> [String: String] { fatalError() } public static func extractAttributes(_ attributeName: String, selector: String, html: String) throws -> [String] { fatalError() } public static func clean(_ html: String) throws -> String { fatalError() } } public enum StudioDOM: Sendable { public static func saveBumpScript(appName: String) -> String { fatalError() } public static func injectPromptScript(prompt: String, autoSubmit: Bool) -> String { fatalError() } public static var turnSentinelScript: String { fatalError() } public static var modelBlowoutSentryScript: String { fatalError() } public static var preferenceVoteSentryScript: String { fatalError() } public static var linkInterceptorScript: String { fatalError() } public static var galleryHarvesterScript: String { fatalError() } }