PureBasic WebGadget — Domains

Overview

The Chromium Framework currently integrates 11 domains, covering 196 commands from the Chrome DevTools Protocol (CDP). While only a subset of the full protocol is implemented, developers can invoke any domain or method by calling the following alternative Procedure:

Cr_WebSocket_Command(Connection, EventID, Method.s, Params.s = #Null$)

Each command requires a Connection, an Event ID, and a Method. The Parameters argument is optional and defaults to #Null$ if omitted.

Example Code:

Params$ = #DQUOTE$ + "features" + #DQUOTE$ + ":[{" +
          #DQUOTE$ + "name" + #DQUOTE$ + ":" + #DQUOTE$ + "prefers-color-scheme" + #DQUOTE$ + "," +
          #DQUOTE$ + "value" + #DQUOTE$ + ":" + #DQUOTE$ + "light" + #DQUOTE$ +
          "}]"
Cr_WebSocket_Command(Connection, 123456, "Emulation.setEmulatedMedia", Params$)

Browser Domain (12)

Commands for interacting with browser-level features such as permissions, windows, and downloads.

Browser_AddPrivacySandboxCoordinatorKeyConfig(Connection, EventID, Api.s, CoordinatorOrigin.s, KeyConfig.s)
Browser_AddPrivacySandboxEnrollmentOverride(Connection, EventID, URL.s)
Browser_CancelDownload(Connection, EventID, GUID.s)
Browser_Close(Connection, EventID)
Browser_GetVersion(Connection, EventID)
Browser_GetBrowserCommandLine(Connection, EventID)
Browser_GetWindowBounds(Connection, EventID, WindowId)
Browser_GetWindowForTarget(Connection, EventID, TargetId.s)
Browser_ResetPermissions(Connection, EventID)
Browser_SetDownloadBehavior(Connection, EventID, Behavior.s)
Browser_SetPermission(Connection, EventID, Permission.s, Setting.s)
Browser_SetWindowBounds(Connection, EventID, WindowId, Bounds.s)

CSS Domain (38)

Read and write CSS stylesheets, rules, and styles, and track computed style updates.

CSS_AddRule(Connection, EventID, StyleSheetId.s, RuleText.s, Location.s)
CSS_CollectClassNames(Connection, EventID, StyleSheetId.s)
CSS_CreateStyleSheet(Connection, EventID, FrameId.s)
CSS_Disable(Connection, EventID)
CSS_Enable(Connection, EventID)
CSS_ForcePseudoState(Connection, EventID, NodeId, ForcedPseudoClasses.s)
CSS_ForceStartingStyle(Connection, EventID, NodeId, Forced)
CSS_GetAnimatedStylesForNode(Connection, EventID, NodeId)
CSS_GetBackgroundColors(Connection, EventID, NodeId)
CSS_GetComputedStyleForNode(Connection, EventID, NodeId)
CSS_GetEnvironmentVariables(Connection, EventID)
CSS_GetInlineStylesForNode(Connection, EventID, NodeId)
CSS_GetLayersForNode(Connection, EventID, NodeId)
CSS_GetLocationForSelector(Connection, EventID, StyleSheetId.s, SelectorText.s)
CSS_GetLonghandProperties(Connection, EventID, ShorthandName.s, Value.s)
CSS_GetMatchedStylesForNode(Connection, EventID, NodeId)
CSS_GetMediaQueries(Connection, EventID)
CSS_GetPlatformFontsForNode(Connection, EventID, NodeId)
CSS_GetStyleSheetText(Connection, EventID, StyleSheetId.s)
CSS_ResolveValues(Connection, EventID, Values.s, NodeId)
CSS_SetContainerQueryConditionText(Connection, EventID, StyleSheetId.s, Range.s, Text.s)
CSS_SetEffectivePropertyValueForNode(Connection, EventID, NodeId, PropertyName.s, Value.s)
CSS_SetKeyframeKey(Connection, EventID, StyleSheetId.s, Range.s, KeyText.s)
CSS_SetLocalFontsEnabled(Connection, EventID, Enabled)
CSS_SetMediaText(Connection, EventID, StyleSheetId.s, Range.s, Text.s)
CSS_SetNavigationText(Connection, EventID, StyleSheetId.s, Range.s, Text.s)
CSS_SetPropertyRulePropertyName(Connection, EventID, StyleSheetId.s, Range.s, PropertyName.s)
CSS_SetRuleSelector(Connection, EventID, StyleSheetId.s, Range.s, Selector.s)
CSS_SetScopeText(Connection, EventID, StyleSheetId.s, Range.s, Text.s)
CSS_SetStyleSheetText(Connection, EventID, StyleSheetId.s, Text.s)
CSS_SetStyleTexts(Connection, EventID, Edits.s)
CSS_SetSupportsText(Connection, EventID, StyleSheetId.s, Range.s, Text.s)
CSS_StartRuleUsageTracking(Connection, EventID)
CSS_StopRuleUsageTracking(Connection, EventID)
CSS_TakeComputedStyleUpdates(Connection, EventID)
CSS_TakeCoverageDelta(Connection, EventID)
CSS_TrackComputedStyleUpdates(Connection, EventID, PropertiesToTrack.s)
CSS_TrackComputedStyleUpdatesForNode(Connection, EventID)

DOM Domain (27)

Access and manipulate the document structure of a webpage.

DOM_DescribeNode(Connection, EventID)
DOM_Disable(Connection, EventID)
DOM_Enable(Connection, EventID)
DOM_Focus(Connection, EventID)
DOM_GetAttributes(Connection, EventID, NodeId)
DOM_GetBoxModel(Connection, EventID)
DOM_GetDocument(Connection, EventID)
DOM_GetNodeForLocation(Connection, EventID, X, Y)
DOM_GetOuterHTML(Connection, EventID)
DOM_HideHighlight(Connection, EventID)
DOM_HighlightNode(Connection, EventID)
DOM_HighlightRect(Connection, EventID)
DOM_MoveTo(Connection, EventID, NodeId, TargetNodeId)
DOM_QuerySelector(Connection, EventID, NodeId, Selector.s)
DOM_QuerySelectorAll(Connection, EventID, NodeId, Selector.s)
DOM_RemoveAttribute(Connection, EventID, NodeId, Name.s)
DOM_RemoveNode(Connection, EventID, NodeId)
DOM_RequestChildNodes(Connection, EventID, NodeId)
DOM_RequestNode(Connection, EventID, ObjectId.s)
DOM_ResolveNode(Connection, EventID)
DOM_ScrollIntoViewIfNeeded(Connection, EventID)
DOM_SetAttributesAsText(Connection, EventID, NodeId, Text.s)
DOM_SetAttributeValue(Connection, EventID, NodeId, Name.s, Value.s)
DOM_SetFileInputFiles(Connection, EventID, Files.s)
DOM_SetNodeName(Connection, EventID, NodeId, Name.s)
DOM_SetNodeValue(Connection, EventID, NodeId, Value.s)
DOM_SetOuterHTML(Connection, EventID, NodeId, OuterHTML.s)

Emulation Domain (19)

Simulate device and environmental conditions such as screen size and geolocation.

Emulation_ClearDeviceMetricsOverride(Connection, EventID)
Emulation_ClearGeolocationOverride(Connection, EventID)
Emulation_ClearIdleOverride(Connection, EventID)
Emulation_ResetPageScaleFactor(Connection, EventID)
Emulation_SetAutoDarkModeOverride(Connection, EventID, Enabled)
Emulation_SetCPUThrottlingRate(Connection, EventID, Rate.f)
Emulation_SetDefaultBackgroundColorOverride(Connection, EventID)
Emulation_SetDeviceMetricsOverride(Connection, EventID, Width, Height, DeviceScaleFactor.f, Mobile)
Emulation_SetEmulatedMedia(Connection, EventID)
Emulation_SetEmulatedOSTextScale(Connection, EventID, Scale.f)
Emulation_SetEmulatedVisionDeficiency(Connection, EventID, Type.s)
Emulation_SetGeolocationOverride(Connection, EventID, Latitude.f, Longitude.f, Accuracy.f)
Emulation_SetIdleOverride(Connection, EventID, IsUserActive, IsScreenUnlocked)
Emulation_SetPageScaleFactor(Connection, EventID, PageScaleFactor.f)
Emulation_SetScriptExecutionDisabled(Connection, EventID, Value)
Emulation_SetScrollbarsHidden(Connection, EventID, Hidden)
Emulation_SetTimezoneOverride(Connection, EventID, TimezoneId.s)
Emulation_SetTouchEmulationEnabled(Connection, EventID, Enabled)
Emulation_SetUserAgentOverride(Connection, EventID, UserAgent.s)

Fetch Domain (8)

Manage network requests, authentication challenges, and response handling.

Fetch_ContinueRequest(Connection, EventID, RequestId.s)
Fetch_ContinueWithAuth(Connection, EventID, RequestId.s, AuthChallengeResponse.s)
Fetch_Disable(Connection, EventID)
Fetch_Enable(Connection, EventID)
Fetch_FailRequest(Connection, EventID, RequestId.s, ErrorReason.s)
Fetch_FulfillRequest(Connection, EventID, RequestId.s, ResponseCode)
Fetch_GetResponseBody(Connection, EventID, RequestId.s)
Fetch_TakeResponseBodyAsStream(Connection, EventID, RequestId.s)

Input Domain (7)

Simulate user input such as keyboard events, mouse interactions, and text entry.

Input_CancelDragging(Connection, EventID)
Input_DispatchKeyEvent(Connection, EventID, Type.s)
Input_DispatchMouseEvent(Connection, EventID, Type.s, X.f, Y.f)
Input_DispatchTouchEvent(Connection, EventID, Type.s, TouchPoints.s)
Input_EmulateTouchFromMouseEvent(Connection, EventID, Type.s, X.f, Y.f, Button.s)
Input_InsertText(Connection, EventID, Text.s)
Input_SetIgnoreInputEvents(Connection, EventID, Ignore)

Network Domain (14)

Control caching, cookies, headers, and user-agent behavior.

Network_ClearBrowserCache(Connection, EventID)
Network_ClearBrowserCookies(Connection, EventID)
Network_DeleteCookies(Connection, EventID, Name.s)
Network_Disable(Connection, EventID)
Network_Enable(Connection, EventID)
Network_GetCookies(Connection, EventID)
Network_GetRequestPostData(Connection, EventID, RequestId.s)
Network_GetResponseBody(Connection, EventID, RequestId.s)
Network_SetBypassServiceWorker(Connection, EventID, Bypass)
Network_SetCacheDisabled(Connection, EventID, CacheDisabled)
Network_SetCookie(Connection, EventID, Name.s, Value.s)
Network_SetCookies(Connection, EventID, Cookies.s)
Network_SetExtraHTTPHeaders(Connection, EventID, Headers.s)
Network_SetUserAgentOverride(Connection, EventID, UserAgent.s)

Overlay Domain (24)

Highlight, display, or hide elements on a web page for debugging and visual inspection.

Overlay_Disable(Connection, EventID)
Overlay_Enable(Connection, EventID)
Overlay_HideHighlight(Connection, EventID)
Overlay_HighlightNode(Connection, EventID, HighlightConfig.s)
Overlay_HighlightQuad(Connection, EventID, Quad.s)
Overlay_HighlightRect(Connection, EventID, X, Y, Width, Height)
Overlay_HighlightSourceOrder(Connection, EventID, SourceOrderConfig.s)
Overlay_SetInspectMode(Connection, EventID, Mode.s, HighlightConfig.s)
Overlay_SetPausedInDebuggerMessage(Connection, EventID)
Overlay_SetShowAdHighlights(Connection, EventID, Show)
Overlay_SetShowContainerQueryOverlays(Connection, EventID, ContainerQueryHighlightConfigs.s)
Overlay_SetShowDebugBorders(Connection, EventID, Show)
Overlay_SetShowFlexOverlays(Connection, EventID, FlexNodeHighlightConfigs.s)
Overlay_SetShowFPSCounter(Connection, EventID, Show)
Overlay_SetShowGridOverlays(Connection, EventID, GridNodeHighlightConfigs.s)
Overlay_SetShowHinge(Connection, EventID)
Overlay_SetShowInspectedElementAnchor(Connection, EventID)
Overlay_SetShowIsolatedElements(Connection, EventID, IsolatedElementHighlightConfigs.s)
Overlay_SetShowLayoutShiftRegions(Connection, EventID, Result)
Overlay_SetShowPaintRects(Connection, EventID, Result)
Overlay_SetShowScrollBottleneckRects(Connection, EventID, Show)
Overlay_SetShowScrollSnapOverlays(Connection, EventID, ScrollSnapHighlightConfigs.s)
Overlay_SetShowViewportSizeOnResize(Connection, EventID, Show)
Overlay_SetShowWindowControlsOverlay(Connection, EventID)

Page Domain (26)

Comprehensive commands for page lifecycle, rendering, navigation, and scripting operations.

Page_AddScriptToEvaluateOnNewDocument(Connection, EventID, Source.s)
Page_BringToFront(Connection, EventID)
Page_CaptureScreenshot(Connection, EventID)
Page_Close(Connection, EventID)
Page_CreateIsolatedWorld(Connection, EventID, FrameId.s)
Page_Disable(Connection, EventID)
Page_Enable(Connection, EventID)
Page_GetAppManifest(Connection, EventID)
Page_GetFrameTree(Connection, EventID)
Page_GetLayoutMetrics(Connection, EventID)
Page_GetNavigationHistory(Connection, EventID)
Page_HandleJavaScriptDialog(Connection, EventID, Accept)
Page_Navigate(Connection, EventID, URL.s)
Page_NavigateToHistoryEntry(Connection, EventID, EntryId)
Page_PrintToPDF(Connection, EventID)
Page_Reload(Connection, EventID)
Page_RemoveScriptToEvaluateOnNewDocument(Connection, EventID, Identifier.s)
Page_ResetNavigationHistory(Connection, EventID)
Page_ScreencastFrameAck(Connection, EventID, SessionId)
Page_SetBypassCSP(Connection, EventID, Enabled)
Page_SetDocumentContent(Connection, EventID, FrameId.s, HTML.s)
Page_SetInterceptFileChooserDialog(Connection, EventID, Enabled)
Page_SetLifecycleEventsEnabled(Connection, EventID, Enabled)
Page_StartScreencast(Connection, EventID)
Page_StopLoading(Connection, EventID)
Page_StopScreencast(Connection, EventID)

Runtime Domain (17)

Execute and manage JavaScript code, bindings, and scripts within the target environment.

Runtime_AddBinding(Connection, EventID, Name.s)
Runtime_AwaitPromise(Connection, EventID, PromiseObjectId.s)
Runtime_CallFunctionOn(Connection, EventID, FunctionDeclaration.s)
Runtime_CompileScript(Connection, EventID, Expression.s, SourceURL.s, PersistScript)
Runtime_Disable(Connection, EventID)
Runtime_DiscardConsoleEntries(Connection, EventID)
Runtime_Enable(Connection, EventID)
Runtime_Evaluate(Connection, EventID, Expression.s)
Runtime_GetProperties(Connection, EventID, ObjectId.s)
Runtime_GlobalLexicalScopeNames(Connection, EventID)
Runtime_QueryObjects(Connection, EventID, PrototypeObjectId.s)
Runtime_ReleaseObject(Connection, EventID, ObjectId.s)
Runtime_ReleaseObjectGroup(Connection, EventID, ObjectGroup.s)
Runtime_RemoveBinding(Connection, EventID, Name.s)
Runtime_RunIfWaitingForDebugger(Connection, EventID)
Runtime_RunScript(Connection, EventID, ScriptId.s)
Runtime_SetAsyncCallStackDepth(Connection, EventID, MaxDepth)

Target Domain (12)

Attach to, manage, or control different browser targets such as tabs or extensions.

Target_ActivateTarget(Connection, EventID, TargetID.s)
Target_AttachToTarget(Connection, EventID, TargetID.s)
Target_CloseTarget(Connection, EventID, TargetID.s)
Target_CreateBrowserContext(Connection, EventID)
Target_CreateTarget(Connection, EventID, URL.s)
Target_DetachFromTarget(Connection, EventID)
Target_DisposeBrowserContext(Connection, EventID, BrowserContextId.s)
Target_GetBrowserContexts(Connection, EventID)
Target_GetTargetInfo(Connection, EventID, TargetID.s)
Target_GetTargets(Connection, EventID)
Target_SetAutoAttach(Connection, EventID, AutoAttach, WaitForDebuggerOnStart)
Target_SetDiscoverTargets(Connection, EventID, Discover)

Command Usage

Executing a command from a specific domain is generally simpler than using the Cr_WebSocket_Command() procedure directly. Each command mirrors the method name, with the domain and command separated by an underscore.

Without Optional Parameters:

Page_CaptureScreenshot(Connection, #UE_Page_CaptureScreenshot)

With Optional Parameters:

NewList params_data.PARAMS_DATA()
AddElement(params_data())
params_data()\Name = "clip"
params_data()\Type = #Cr_DataType_Object
params_data()\Input = "{" +
                       #DQUOTE$ + "x" + #DQUOTE$ + ":0," +
                       #DQUOTE$ + "y" + #DQUOTE$ + ":0," +
                       #DQUOTE$ + "width" + #DQUOTE$ + ":" + Str(Width) + "," +
                       #DQUOTE$ + "height" + #DQUOTE$ + ":" + Str(Height) + "," +
                       #DQUOTE$ + "scale" + #DQUOTE$ + ":" + StrF(Scale, 2) +
                       "}"
AddElement(params_data())
params_data()\Name = "captureBeyondViewport"
params_data()\Type = #Cr_DataType_Boolean
params_data()\Input = "true"
Page_CaptureScreenshot(Connection, #UE_Page_CaptureScreenshot, params_data())