chrome-devtools-kotlin / org.hildan.chrome.devtools.domains.page / PageDomain

PageDomain

class PageDomain

Actions and events related to the inspected page belong to the page domain.

Official doc

Functions

addCompilationCache

Seeds compilation cache for given url. Compilation cache does not survive cross-process navigation.

suspend fun addCompilationCache(input: AddCompilationCacheRequest): Unit

addScriptToEvaluateOnLoad

Deprecated, please use addScriptToEvaluateOnNewDocument instead.

suspend fun addScriptToEvaluateOnLoad(input: AddScriptToEvaluateOnLoadRequest): AddScriptToEvaluateOnLoadResponse

addScriptToEvaluateOnNewDocument

Evaluates given script in every frame upon creation (before loading frame's scripts).

suspend fun addScriptToEvaluateOnNewDocument(input: AddScriptToEvaluateOnNewDocumentRequest): AddScriptToEvaluateOnNewDocumentResponse

bringToFront

Brings page to front (activates tab).

suspend fun bringToFront(): Unit

captureScreenshot

Capture page screenshot.

suspend fun captureScreenshot(input: CaptureScreenshotRequest): CaptureScreenshotResponse

captureSnapshot

Returns a snapshot of the page as a string. For MHTML format, the serialization includes iframes, shadow DOM, external resources, and element-inline styles.

suspend fun captureSnapshot(input: CaptureSnapshotRequest): CaptureSnapshotResponse

clearCompilationCache

Clears seeded compilation cache.

suspend fun clearCompilationCache(): Unit

clearDeviceMetricsOverride

Clears the overriden device metrics.

suspend fun clearDeviceMetricsOverride(): Unit

clearDeviceOrientationOverride

Clears the overridden Device Orientation.

suspend fun clearDeviceOrientationOverride(): Unit

clearGeolocationOverride

Clears the overriden Geolocation Position and Error.

suspend fun clearGeolocationOverride(): Unit

close

Tries to close page, running its beforeunload hooks, if any.

suspend fun close(): Unit

compilationCacheProduced

Issued for every compilation cache generated. Is only available if Page.setGenerateCompilationCache is enabled.

fun compilationCacheProduced(): Flow<CompilationCacheProducedEvent>

crash

Crashes renderer on the IO thread, generates minidumps.

suspend fun crash(): Unit

createIsolatedWorld

Creates an isolated world for the given frame.

suspend fun createIsolatedWorld(input: CreateIsolatedWorldRequest): CreateIsolatedWorldResponse

deleteCookie

Deletes browser cookie with given name, domain and path.

suspend fun deleteCookie(input: DeleteCookieRequest): Unit

disable

Disables page domain notifications.

suspend fun disable(): Unit

domContentEventFired

Official doc

fun domContentEventFired(): Flow<DomContentEventFiredEvent>

downloadProgress

Fired when download makes progress. Last call has |done| == true.

fun downloadProgress(): Flow<DownloadProgressEvent>

downloadWillBegin

Fired when page is about to start a download.

fun downloadWillBegin(): Flow<DownloadWillBeginEvent>

enable

Enables page domain notifications.

suspend fun enable(): Unit

events

Subscribes to all events related to this domain.

fun events(): Flow<PageEvent>

fileChooserOpened

Emitted only when page.interceptFileChooser is enabled.

fun fileChooserOpened(): Flow<FileChooserOpenedEvent>

frameAttached

Fired when frame has been attached to its parent.

fun frameAttached(): Flow<FrameAttachedEvent>

frameClearedScheduledNavigation

Fired when frame no longer has a scheduled navigation.

fun frameClearedScheduledNavigation(): Flow<FrameClearedScheduledNavigationEvent>

frameDetached

Fired when frame has been detached from its parent.

fun frameDetached(): Flow<FrameDetachedEvent>

frameNavigated

Fired once navigation of the frame has completed. Frame is now associated with the new loader.

fun frameNavigated(): Flow<FrameNavigatedEvent>

frameRequestedNavigation

Fired when a renderer-initiated navigation is requested. Navigation may still be cancelled after the event is issued.

fun frameRequestedNavigation(): Flow<FrameRequestedNavigationEvent>

frameResized

Official doc

fun frameResized(): Flow<FrameResizedEvent>

frameScheduledNavigation

Fired when frame schedules a potential navigation.

fun frameScheduledNavigation(): Flow<FrameScheduledNavigationEvent>

frameStartedLoading

Fired when frame has started loading.

fun frameStartedLoading(): Flow<FrameStartedLoadingEvent>

frameStoppedLoading

Fired when frame has stopped loading.

fun frameStoppedLoading(): Flow<FrameStoppedLoadingEvent>

generateTestReport

Generates a report for testing.

suspend fun generateTestReport(input: GenerateTestReportRequest): Unit

getAppManifest

Official doc

suspend fun getAppManifest(): GetAppManifestResponse

getCookies

Returns all browser cookies. Depending on the backend support, will return detailed cookie information in the cookies field.

suspend fun getCookies(): GetCookiesResponse

getFrameTree

Returns present frame tree structure.

suspend fun getFrameTree(): GetFrameTreeResponse

getInstallabilityErrors

Official doc

suspend fun getInstallabilityErrors(): GetInstallabilityErrorsResponse

getLayoutMetrics

Returns metrics relating to the layouting of the page, such as viewport bounds/scale.

suspend fun getLayoutMetrics(): GetLayoutMetricsResponse

getManifestIcons

Official doc

suspend fun getManifestIcons(): GetManifestIconsResponse

getNavigationHistory

Returns navigation history for the current page.

suspend fun getNavigationHistory(): GetNavigationHistoryResponse

getResourceContent

Returns content of the given resource.

suspend fun getResourceContent(input: GetResourceContentRequest): GetResourceContentResponse

getResourceTree

Returns present frame / resource tree structure.

suspend fun getResourceTree(): GetResourceTreeResponse

handleJavaScriptDialog

Accepts or dismisses a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload).

suspend fun handleJavaScriptDialog(input: HandleJavaScriptDialogRequest): Unit

interstitialHidden

Fired when interstitial page was hidden

fun interstitialHidden(): Flow<InterstitialHiddenEvent>

interstitialShown

Fired when interstitial page was shown

fun interstitialShown(): Flow<InterstitialShownEvent>

javascriptDialogClosed

Fired when a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload) has been closed.

fun javascriptDialogClosed(): Flow<JavascriptDialogClosedEvent>

javascriptDialogOpening

Fired when a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload) is about to open.

fun javascriptDialogOpening(): Flow<JavascriptDialogOpeningEvent>

lifecycleEvent

Fired for top level page lifecycle events such as navigation, load, paint, etc.

fun lifecycleEvent(): Flow<LifecycleEventEvent>

loadEventFired

Official doc

fun loadEventFired(): Flow<LoadEventFiredEvent>

navigate

Navigates current page to the given URL.

suspend fun navigate(input: NavigateRequest): NavigateResponse

navigatedWithinDocument

Fired when same-document navigation happens, e.g. due to history API usage or anchor navigation.

fun navigatedWithinDocument(): Flow<NavigatedWithinDocumentEvent>

navigateToHistoryEntry

Navigates current page to the given history entry.

suspend fun navigateToHistoryEntry(input: NavigateToHistoryEntryRequest): Unit

printToPDF

Print page as PDF.

suspend fun printToPDF(input: PrintToPDFRequest): PrintToPDFResponse

reload

Reloads given page optionally ignoring the cache.

suspend fun reload(input: ReloadRequest): Unit

removeScriptToEvaluateOnLoad

Deprecated, please use removeScriptToEvaluateOnNewDocument instead.

suspend fun removeScriptToEvaluateOnLoad(input: RemoveScriptToEvaluateOnLoadRequest): Unit

removeScriptToEvaluateOnNewDocument

Removes given script from the list.

suspend fun removeScriptToEvaluateOnNewDocument(input: RemoveScriptToEvaluateOnNewDocumentRequest): Unit

resetNavigationHistory

Resets navigation history for the current page.

suspend fun resetNavigationHistory(): Unit

screencastFrame

Compressed image data requested by the startScreencast.

fun screencastFrame(): Flow<ScreencastFrameEvent>

screencastFrameAck

Acknowledges that a screencast frame has been received by the frontend.

suspend fun screencastFrameAck(input: ScreencastFrameAckRequest): Unit

screencastVisibilityChanged

Fired when the page with currently enabled screencast was shown or hidden `.

fun screencastVisibilityChanged(): Flow<ScreencastVisibilityChangedEvent>

searchInResource

Searches for given string in resource content.

suspend fun searchInResource(input: SearchInResourceRequest): SearchInResourceResponse

setAdBlockingEnabled

Enable Chrome's experimental ad filter on all sites.

suspend fun setAdBlockingEnabled(input: SetAdBlockingEnabledRequest): Unit

setBypassCSP

Enable page Content Security Policy by-passing.

suspend fun setBypassCSP(input: SetBypassCSPRequest): Unit

setDeviceMetricsOverride

Overrides the values of device screen dimensions (window.screen.width, window.screen.height, window.innerWidth, window.innerHeight, and "device-width"/"device-height"-related CSS media query results).

suspend fun setDeviceMetricsOverride(input: SetDeviceMetricsOverrideRequest): Unit

setDeviceOrientationOverride

Overrides the Device Orientation.

suspend fun setDeviceOrientationOverride(input: SetDeviceOrientationOverrideRequest): Unit

setDocumentContent

Sets given markup as the document's HTML.

suspend fun setDocumentContent(input: SetDocumentContentRequest): Unit

setDownloadBehavior

Set the behavior when downloading a file.

suspend fun setDownloadBehavior(input: SetDownloadBehaviorRequest): Unit

setFontFamilies

Set generic font families.

suspend fun setFontFamilies(input: SetFontFamiliesRequest): Unit

setFontSizes

Set default font sizes.

suspend fun setFontSizes(input: SetFontSizesRequest): Unit

setGeolocationOverride

Overrides the Geolocation Position or Error. Omitting any of the parameters emulates position unavailable.

suspend fun setGeolocationOverride(input: SetGeolocationOverrideRequest): Unit

setInterceptFileChooserDialog

Intercept file chooser requests and transfer control to protocol clients. When file chooser interception is enabled, native file chooser dialog is not shown. Instead, a protocol event Page.fileChooserOpened is emitted.

suspend fun setInterceptFileChooserDialog(input: SetInterceptFileChooserDialogRequest): Unit

setLifecycleEventsEnabled

Controls whether page will emit lifecycle events.

suspend fun setLifecycleEventsEnabled(input: SetLifecycleEventsEnabledRequest): Unit

setProduceCompilationCache

Forces compilation cache to be generated for every subresource script.

suspend fun setProduceCompilationCache(input: SetProduceCompilationCacheRequest): Unit

setTouchEmulationEnabled

Toggles mouse event-based touch event emulation.

suspend fun setTouchEmulationEnabled(input: SetTouchEmulationEnabledRequest): Unit

setWebLifecycleState

Tries to update the web lifecycle state of the page. It will transition the page to the given state according to: https://github.com/WICG/web-lifecycle/

suspend fun setWebLifecycleState(input: SetWebLifecycleStateRequest): Unit

startScreencast

Starts sending each frame using the screencastFrame event.

suspend fun startScreencast(input: StartScreencastRequest): Unit

stopLoading

Force the page stop all navigations and pending resource fetches.

suspend fun stopLoading(): Unit

stopScreencast

Stops sending each frame in the screencastFrame.

suspend fun stopScreencast(): Unit

waitForDebugger

Pauses page execution. Can be resumed using generic Runtime.runIfWaitingForDebugger.

suspend fun waitForDebugger(): Unit

windowOpen

Fired when a new window is going to be opened, via window.open(), link click, form submission, etc.

fun windowOpen(): Flow<WindowOpenEvent>

Extension Functions

captureScreenshotToFile

Captures a screenshot of the current page based on the given request, and store the resulting image into a new file at the given outputImagePath.

suspend fun PageDomain.captureScreenshotToFile(outputImagePath: Path, request: CaptureScreenshotRequest = CaptureScreenshotRequest()): Unit

navigateAndWaitLoading

Navigates the current page according to the provided url, and suspends until the corresponding frameStoppedLoading event is received.

suspend fun PageDomain.navigateAndWaitLoading(url: String): Unit

Navigates the current page according to the provided navigateRequest, and suspends until the corresponding frameStoppedLoading event is received.

suspend fun PageDomain.navigateAndWaitLoading(navigateRequest: NavigateRequest): Unit