Package Torello.Browser.BrowserAPI
Class Emulation
- java.lang.Object
-
- Torello.Browser.BrowserAPI.Emulation
-
public class Emulation extends java.lang.Object
This class was built using the Chrome Remote Dev-Tools A.P.I., which is specified by two JSON-RPC Files. These files were obtained from the Chrome Dev Tools Protocol Git Hub Page, which has a "Tip of Tree" (the latest) API-Specification Page Here: JSON-RPC Protocol Specification.
These files were converted into this Java-Browser (CDP) Library. The intention is to have them function in a similar fasion to the Node.js Tool known as 'Puppeteer', Microsoft's 'Playwright' and of course the Main-Stay 'Selenium.' The Java-HTML JAR Library merely implements the Java Types & Commands defined by Google's DevTools Protocol.
🧠 View the Google CDP API:
This domain emulates different environments for the page.
The top-level description and explanation for this class (this comment, at the top this Java-Doc Page) is repeated, verbatim, across all of the domain classes which comprise Google's CDP API.This class is intended to be used with a Browser Instance
These methods have been tested, to some degree, using Google Chrome. In order to use this class you must start a web-browser instance and make a connection to the browser using aRemote Debugging Port. Google-Corporation is the developer of this API, but any browser which accepts a Remote Debug Port Connection over Web-Sockets.
Google-Chrome was used during the development process of the classes in this particular package. Lately, it has been asserted Microsoft has switched to using the Chrome Browser-Engine for its Microsoft Edge Internal Code-Base. Therefore, there may some functionality available when running the methods in this class with Microsoft-Edge.
Check whether the your Web-Browser will allow itself to be driven by theWeb-Socket RDP-Port 9223. See the examples available in packageTorello.Browserto undertand how to build aPageConnandBrowserConnWeb-Socket Connection, and how to build aWebSocketSenderinstance in order to execute the methods in this class.
Web-Socket & JSON API:
Every one of the methods that reside in this class are designed to do nothing more than:- Accept Parameters from the User, and "Marshall Them" into a Valid JSON-Request
- Transmit the Marshalled Request-JSON to a Headless Web-Browser over a Web-Socket Connection
- Receive BOTH that Command-Results AND any Browser Event-Firings from the Web-Socket
- Parse JSON Method-Results and Browser-Event Firings, and Subsequently Convert them to Standard Java-Types
- Report these Method-Results and Browser-Events to the User via a User-Registered, Event-Listener (Events) or a Promise Object (Command Responses / Results)
Unlike the bulk of the Java HTML JAR Library, there is very little native Java-Code, and very little testing that may be done on any of the classes & methods in this package. The code inside these classes does nothing more than marshall-and-unmarshall Java-Types into Json-Requests (and vice-versa). The Java-Script & Browser modules inside of a Google-Chrome instance are, theoretically, handling these requests, and returning their results (or events) over the Web-Socket Connection.
It has been asserted (by Google Chrome Developers) that some of these methods are only "partially working" or "experimental".
Asking Chat-GPT for Help:
The LLM otherwise known as "Chat-GPT" does, indeed, have an expert level of knowledge about the "Remote DevTools Protocol". The API that theChrome DevTools Protocl (CDP)exports is extremely well understood by the LLM, and generally I have found that Chat-GPT understands (by 2 or 3 orders of magnitude) better what my Auto-Generated JSON-Wrappers can do in controlling a Web-Browser than I could ever possibly hope to understand.
Though not available today, there will soon be an automatically downloadable Token-Stream (AI Embeddings) BUTTON available on my Java-Doc Pages that should hopefully make it extremely easy to post my code-base, RAG Style, to Chat-GPT and other LLM's when 'interogating' them. Presently, because my "Get Token Stream Button" does not exist yet on any of my pages, what you can do is copy-and-paste any Method-Signature from any one of these pages and then ask Chat-GPT to explain what that Browser or Java-Script Function is actually doing. It is very likely to give you some pretty neat answers.
I have found that every single one of the Domains, Types & Events which are offered by the CDP Protocol (though not documented very well by Google), are perfectly understood by the A.I. LLM - literally to the point where it does know (much better than I ever could) what my own code base actually does!
Try it out, it's a lot of fun. Note that this package and these classes were originally developed solely to be able to execute the Java-Script that a browser executes when visiting a Web-Site. Complete HTML-Page Content can be scraped (using the HTML Data-Scraping Tools in Java-HTML) off of Web-Sites that have dynamic / Java-Script Generated Content.
Conspicuous Boxed-Types Usage:
You may notice that there are many methods that have parameters which accept, for instance, anInteger, instead of a primitiveint. Just to remind the readiner, in Java Programs aBoxed Typeis a standard Java-Primitive which has been converted into an Object-Reference. The use of Boxed-Types in this code base is an easy-and-fast-way to allow for the concept of "Optional Parameters" or "Optional Field Value."
Whenever you see a method that accepts anInteger, the reason for this Parameter-Type choice is actually to allow a user to pass 'null' to it. This is a simple way to ELIDE passing any value at all to parameters which Google-Chrome would otherwise assert are "Optional." Whenever you pass 'null' to a Boxed-Types in this class, the Json-Processor will simply eliminate that Object-Property from the command altogether; and the browser will simply not receive any value for that parameter when that command is invoked.
The Java Language Specification does not have an easy or well defined means of accepting optional method parameters; so Boxed-Types and 'null' are utilized here. Note that 'null' may be passed to any Command Method-Parameter that is listed asOptionalon the Java-Doc Page description for that parameter.
Hi-Lited Source-Code:This File's Source Code:
- View Here: Torello/Browser/BrowserAPI/Emulation.java
- Open New Browser-Tab: Torello/Browser/BrowserAPI/Emulation.java
File Size: 95,285 Bytes Line Count: 2,336 '\n' Characters Found
Helper: Command Invocation Helpers
- View Here: Emulation$$Commands.java
- Open New Browser-Tab: Emulation$$Commands.java
File Size: 9,017 Bytes Line Count: 192 '\n' Characters Found
Stateless Class:This class neither contains any program-state, nor can it be instantiated. The@StaticFunctionalAnnotation may also be called 'The Spaghetti Report'.Static-Functionalclasses are, essentially, C-Styled Files, without any constructors or non-static member fields. It is a concept very similar to the Java-Bean's@StatelessAnnotation.
- 1 Constructor(s), 1 declared private, zero-argument constructor
- 45 Method(s), 45 declared static
- 6 Field(s), 6 declared static, 6 declared final
-
-
Nested Class Summary
Type Nested Classes: Types / Classes that Are Used & Exported by this Domain Modifier and Type Class Description static classEmulation.DevicePosture[No Description Provided by Google]static classEmulation.DisplayFeature[No Description Provided by Google]static classEmulation.MediaFeature[No Description Provided by Google]static classEmulation.PressureMetadata[No Description Provided by Google]static classEmulation.SafeAreaInsets[No Description Provided by Google]static classEmulation.ScreenOrientationScreen orientation.static classEmulation.SensorMetadata[No Description Provided by Google]static classEmulation.SensorReading[No Description Provided by Google]static classEmulation.SensorReadingQuaternion[No Description Provided by Google]static classEmulation.SensorReadingSingle[No Description Provided by Google]static classEmulation.SensorReadingXYZ[No Description Provided by Google]static classEmulation.UserAgentBrandVersionUsed to specify User Agent Client Hints to emulate.static classEmulation.UserAgentMetadataUsed to specify User Agent Client Hints to emulate.
-
Field Summary
Enumerated Strings: Like Java 'enum' Types, but Converted to Read-Only String-Lists Modifier and Type Field Description static ReadOnlyList<String>DisabledImageTypeEnum of image types that can be disabled.static ReadOnlyList<String>PressureSource[No Description Provided by Google]static ReadOnlyList<String>PressureState[No Description Provided by Google]static ReadOnlyList<String>SensorTypeUsed to specify sensor types to emulate.static ReadOnlyList<String>VirtualTimePolicyadvance: If the scheduler runs out of immediate work, the virtual time base may fast forward to allow the next delayed task (if any) to run; pause: The virtual time base may not advance; pauseIfNetworkFetchesPending: The virtual time base may not advance if there are any pending resource fetches.Marker Events: Events without any Fields or Properties Modifier and Type Field Description static StringvirtualTimeBudgetExpiredNotification sent after the virtual time budget for the current VirtualTimePolicy has run out.
-
Method Summary
Emulation Domain Commands Script Returns Modifier and Type Method Booleanstatic Script<>canEmulate()
Tells whether emulation is supported.Voidstatic Script<>clearDeviceMetricsOverride()
Clears the overridden device metrics.Voidstatic Script<>clearDevicePostureOverride()
Clears a device posture override set with either setDeviceMetricsOverride() or setDevicePostureOverride() and starts using posture information from the platform again.Voidstatic Script<>clearDisplayFeaturesOverride()
Clears the display features override set with either setDeviceMetricsOverride() or setDisplayFeaturesOverride() and starts using display features from the platform again.Voidstatic Script<>clearGeolocationOverride()
Clears the overridden Geolocation Position and Error.Voidstatic Script<>clearIdleOverride()
Clears Idle state overrides.Numberstatic Script<>getOverriddenSensorInformation(String type)
[No Description Provided by Google]Voidstatic Script<>resetPageScaleFactor()
Requests that page scale factor is reset to initial values.Voidstatic Script<>setAutoDarkModeOverride(Boolean enabled)
Automatically render all web contents using a dark theme.Voidstatic Script<>setAutomationOverride(boolean enabled)
Allows overriding the automation flag.Voidstatic Script<>setCPUThrottlingRate(Number rate)
Enables CPU throttling to emulate slow CPUs.Voidstatic Script<>setDataSaverOverride(Boolean dataSaverEnabled)
Override the value of navigator.connection.saveDataVoidstatic Script<>setDefaultBackgroundColorOverride(DOM.RGBA color)
Sets or clears an override of the default background color of the frame.Voidstatic Script<>setDeviceMetricsOverride(int width, int height, Number deviceScaleFactor, boolean mobile, Number scale, Integer screenWidth, Integer screenHeight, Integer positionX, Integer positionY, Boolean dontSetVisibleSize, Emulation.ScreenOrientation screenOrientation, Page.Viewport viewport, Emulation.DisplayFeature displayFeature, Emulation.DevicePosture devicePosture)
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).Voidstatic Script<>setDevicePostureOverride(Emulation.DevicePosture posture)
Start reporting the given posture value to the Device Posture API.Voidstatic Script<>setDisabledImageTypes(String[] imageTypes)
[No Description Provided by Google]Voidstatic Script<>setDisplayFeaturesOverride(Emulation.DisplayFeature[] features)
Start using the given display features to pupulate the Viewport Segments API.Voidstatic Script<>setDocumentCookieDisabled(boolean disabled)
[No Description Provided by Google]Voidstatic Script<>setEmitTouchEventsForMouse(boolean enabled, String configuration)
[No Description Provided by Google]Voidstatic Script<>setEmulatedMedia(String media, Emulation.MediaFeature[] features)
Emulates the given media type or media feature for CSS media queries.Voidstatic Script<>setEmulatedOSTextScale(Number scale)
Emulates the given OS text scale.Voidstatic Script<>setEmulatedVisionDeficiency(String type)
Emulates the given vision deficiency.Voidstatic Script<>setFocusEmulationEnabled(boolean enabled)
Enables or disables simulating a focused and active page.Voidstatic Script<>setGeolocationOverride(Number latitude, Number longitude, Number accuracy, Number altitude, Number altitudeAccuracy, Number heading, Number speed)
Overrides the Geolocation Position or Error.Voidstatic Script<>setHardwareConcurrencyOverride(int hardwareConcurrency)
[No Description Provided by Google]Voidstatic Script<>setIdleOverride(boolean isUserActive, boolean isScreenUnlocked)
Overrides the Idle state.Voidstatic Script<>setLocaleOverride(String locale)
Overrides default host system locale with the specified one.Voidstatic Script<>setNavigatorOverrides(String platform)
Overrides value returned by the javascript navigator object.Voidstatic Script<>setPageScaleFactor(Number pageScaleFactor)
Sets a specified page scale factor.Voidstatic Script<>setPressureDataOverride(String source, String state, Number ownContributionEstimate)
Provides a given pressure data set that will be processed and eventually be delivered to PressureObserver users.Voidstatic Script<>setPressureSourceOverrideEnabled(boolean enabled, String source, Emulation.PressureMetadata metadata)
Overrides a pressure source of a given type, as used by the Compute Pressure API, so that updates to PressureObserver.observe() are provided via setPressureStateOverride instead of being retrieved from platform-provided telemetry data.Voidstatic Script<>setPressureStateOverride(String source, String state)
TODO: OBSOLETE: To remove when setPressureDataOverride is merged.Voidstatic Script<>setSafeAreaInsetsOverride(Emulation.SafeAreaInsets insets)
Overrides the values for env(safe-area-inset-*) and env(safe-area-max-inset-*).Voidstatic Script<>setScriptExecutionDisabled(boolean value)
Switches script execution in the page.Voidstatic Script<>setScrollbarsHidden(boolean hidden)
[No Description Provided by Google]Voidstatic Script<>setSensorOverrideEnabled(boolean enabled, String type, Emulation.SensorMetadata metadata)
Overrides a platform sensor of a given type.Voidstatic Script<>setSensorOverrideReadings(String type, Emulation.SensorReading reading)
Updates the sensor readings reported by a sensor type previously overridden by setSensorOverrideEnabled.Voidstatic Script<>setSmallViewportHeightDifferenceOverride(int difference)
Allows overriding the difference between the small and large viewport sizes, which determine the value of thesvhandlvhunit, respectively.Voidstatic Script<>setTimezoneOverride(String timezoneId)
Overrides default host system timezone with the specified one.Voidstatic Script<>setTouchEmulationEnabled(boolean enabled, Integer maxTouchPoints)
Enables touch on platforms which do not support them.Voidstatic Script<>setUserAgentOverride(String userAgent, String acceptLanguage, String platform, Emulation.UserAgentMetadata userAgentMetadata)
Allows overriding user agent with the given string.Numberstatic Script<>setVirtualTimePolicy(String policy, Number budget, Integer maxVirtualTimeTaskStarvationCount, Number initialVirtualTime)
Turns on virtual time for all frames (replacing real-time with a synthetic time source) and sets the current virtual time policy.Voidstatic Script<>setVisibleSize(int width, int height)
Resizes the frame/viewport of the page.Emulation Domain CommandBuilder Methods Modifier and Type Method Description static CommandBuilder
<Void>setDeviceMetricsOverride()Creates a buider for conveniently assigning parameters to this method.static CommandBuilder
<Void>setGeolocationOverride()Creates a buider for conveniently assigning parameters to this method.
-
-
-
Field Detail
-
virtualTimeBudgetExpired
public static final java.lang.String virtualTimeBudgetExpired
Notification sent after the virtual time budget for the current VirtualTimePolicy has run out.
EXPERIMENTAL
This is Marker-Event. Marker-Event's are events that do not possess any data or fields at all. When such events are fired by the browser, the Web-Socket sends nothing more than the name of the event in the packet. The Java-HTML CDP Implementation (this library) has not actually created a dedicated Java Event-Type for this Browser Event.
This specificstaticfield is actually just declared aString.virtualTimeBudgetExpiredhas not been 'reified' into an actual nested / inner class of its own, at all.
Eliminated Event Type- See Also:
- Constant Field Values
-
DisabledImageType
public static final ReadOnlyList<java.lang.String> DisabledImageType
Enum of image types that can be disabled.
EXPERIMENTAL
String-Enumeration Type
-
PressureSource
public static final ReadOnlyList<java.lang.String> PressureSource
[No Description Provided by Google]
EXPERIMENTAL
String-Enumeration Type
-
PressureState
public static final ReadOnlyList<java.lang.String> PressureState
[No Description Provided by Google]
EXPERIMENTAL
String-Enumeration Type
-
SensorType
public static final ReadOnlyList<java.lang.String> SensorType
Used to specify sensor types to emulate. See https://w3c.github.io/sensors/#automation for more information.
EXPERIMENTAL
String-Enumeration Type
-
VirtualTimePolicy
public static final ReadOnlyList<java.lang.String> VirtualTimePolicy
advance: If the scheduler runs out of immediate work, the virtual time base may fast forward to allow the next delayed task (if any) to run; pause: The virtual time base may not advance; pauseIfNetworkFetchesPending: The virtual time base may not advance if there are any pending resource fetches.
EXPERIMENTAL
String-Enumeration Type
-
-
Method Detail
-
canEmulate
public static Script<java.lang.Boolean> canEmulate()
Tells whether emulation is supported.
DEPRECATED- Returns:
- An instance of
Script<Boolean>
This script may be executed, usingScript.exec, and afterwards, aPromise<Boolean>will be returned
Finally, thePromisemay be awaited, usingPromise.await(), and the returned result of this Browser Function may be retrieved.This Browser Function'sPromisereturns:Boolean (result)
True if emulation is supported.
-
clearDeviceMetricsOverride
public static Script<java.lang.Void> clearDeviceMetricsOverride()
Clears the overridden device metrics.
-
clearDevicePostureOverride
public static Script<java.lang.Void> clearDevicePostureOverride()
Clears a device posture override set with either setDeviceMetricsOverride() or setDevicePostureOverride() and starts using posture information from the platform again. Does nothing if no override is set.
EXPERIMENTAL
-
clearDisplayFeaturesOverride
public static Script<java.lang.Void> clearDisplayFeaturesOverride()
Clears the display features override set with either setDeviceMetricsOverride() or setDisplayFeaturesOverride() and starts using display features from the platform again. Does nothing if no override is set.
EXPERIMENTAL
-
clearGeolocationOverride
public static Script<java.lang.Void> clearGeolocationOverride()
Clears the overridden Geolocation Position and Error.
-
clearIdleOverride
public static Script<java.lang.Void> clearIdleOverride()
Clears Idle state overrides.
-
getOverriddenSensorInformation
public static Script<java.lang.Number> getOverriddenSensorInformation (java.lang.String type)
[No Description Provided by Google]
EXPERIMENTAL- Parameters:
type- -- Returns:
- An instance of
Script<Number>
This script may be executed, usingScript.exec, and afterwards, aPromise<Number>will be returned
Finally, thePromisemay be awaited, usingPromise.await(), and the returned result of this Browser Function may be retrieved.This Browser Function'sPromisereturns:Number (requestedSamplingFrequency)
-
resetPageScaleFactor
public static Script<java.lang.Void> resetPageScaleFactor()
Requests that page scale factor is reset to initial values.
EXPERIMENTAL
-
setAutoDarkModeOverride
public static Script<java.lang.Void> setAutoDarkModeOverride (java.lang.Boolean enabled)
Automatically render all web contents using a dark theme.
EXPERIMENTAL- Parameters:
enabled- Whether to enable or disable automatic dark mode. If not specified, any existing override will be cleared.
OPTIONAL- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setAutomationOverride
public static Script<java.lang.Void> setAutomationOverride (boolean enabled)
Allows overriding the automation flag.
EXPERIMENTAL- Parameters:
enabled- Whether the override should be enabled.- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setCPUThrottlingRate
public static Script<java.lang.Void> setCPUThrottlingRate (java.lang.Number rate)
Enables CPU throttling to emulate slow CPUs.- Parameters:
rate- Throttling rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc).- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setDataSaverOverride
public static Script<java.lang.Void> setDataSaverOverride (java.lang.Boolean dataSaverEnabled)
Override the value of navigator.connection.saveData
EXPERIMENTAL- Parameters:
dataSaverEnabled- Override value. Omitting the parameter disables the override.
OPTIONAL- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setDefaultBackgroundColorOverride
public static Script<java.lang.Void> setDefaultBackgroundColorOverride (DOM.RGBA color)
Sets or clears an override of the default background color of the frame. This override is used if the content does not specify one.- Parameters:
color- RGBA of the default background color. If not specified, any existing override will be cleared.
OPTIONAL- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setDeviceMetricsOverride
public static Script<java.lang.Void> setDeviceMetricsOverride (int width, int height, java.lang.Number deviceScaleFactor, boolean mobile, java.lang.Number scale, java.lang.Integer screenWidth, java.lang.Integer screenHeight, java.lang.Integer positionX, java.lang.Integer positionY, java.lang.Boolean dontSetVisibleSize, Emulation.ScreenOrientation screenOrientation, Page.Viewport viewport, Emulation.DisplayFeature displayFeature, Emulation.DevicePosture devicePosture)
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).👍 Because of the sheer number of input parameters to this method, there is a aCommandBuildervariant to this method which may be invoked instead.
Please View:setDeviceMetricsOverride()- Parameters:
width- Overriding width value in pixels (minimum 0, maximum 10000000). 0 disables the override.height- Overriding height value in pixels (minimum 0, maximum 10000000). 0 disables the override.deviceScaleFactor- Overriding device scale factor value. 0 disables the override.mobile- Whether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text autosizing and more.scale- Scale to apply to resulting view image.
OPTIONALEXPERIMENTALscreenWidth- Overriding screen width value in pixels (minimum 0, maximum 10000000).
OPTIONALEXPERIMENTALscreenHeight- Overriding screen height value in pixels (minimum 0, maximum 10000000).
OPTIONALEXPERIMENTALpositionX- Overriding view X position on screen in pixels (minimum 0, maximum 10000000).
OPTIONALEXPERIMENTALpositionY- Overriding view Y position on screen in pixels (minimum 0, maximum 10000000).
OPTIONALEXPERIMENTALdontSetVisibleSize- Do not set visible view size, rely upon explicit setVisibleSize call.
OPTIONALEXPERIMENTALscreenOrientation- Screen orientation override.
OPTIONALviewport- If set, the visible area of the page will be overridden to this viewport. This viewport change is not observed by the page, e.g. viewport-relative elements do not change positions.
OPTIONALEXPERIMENTALdisplayFeature- If set, the display feature of a multi-segment screen. If not set, multi-segment support is turned-off. Deprecated, use Emulation.setDisplayFeaturesOverride.
OPTIONALEXPERIMENTALDEPRECATEDdevicePosture- If set, the posture of a foldable device. If not set the posture is set to continuous. Deprecated, use Emulation.setDevicePostureOverride.
OPTIONALEXPERIMENTALDEPRECATED- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setDevicePostureOverride
public static Script<java.lang.Void> setDevicePostureOverride (Emulation.DevicePosture posture)
Start reporting the given posture value to the Device Posture API. This override can also be set in setDeviceMetricsOverride().
EXPERIMENTAL- Parameters:
posture- -- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setDisabledImageTypes
public static Script<java.lang.Void> setDisabledImageTypes (java.lang.String[] imageTypes)
[No Description Provided by Google]
EXPERIMENTAL- Parameters:
imageTypes- Image types to disable.- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setDisplayFeaturesOverride
public static Script<java.lang.Void> setDisplayFeaturesOverride (Emulation.DisplayFeature[] features)
Start using the given display features to pupulate the Viewport Segments API. This override can also be set in setDeviceMetricsOverride().
EXPERIMENTAL- Parameters:
features- -- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setDocumentCookieDisabled
public static Script<java.lang.Void> setDocumentCookieDisabled (boolean disabled)
[No Description Provided by Google]
EXPERIMENTAL- Parameters:
disabled- Whether document.coookie API should be disabled.- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setEmitTouchEventsForMouse
public static Script<java.lang.Void> setEmitTouchEventsForMouse (boolean enabled, java.lang.String configuration)
[No Description Provided by Google]
EXPERIMENTAL- Parameters:
enabled- Whether touch emulation based on mouse input should be enabled.configuration- Touch/gesture events configuration. Default: current platform.
Acceptable Values: ["desktop", "mobile"]
OPTIONAL- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setEmulatedMedia
public static Script<java.lang.Void> setEmulatedMedia (java.lang.String media, Emulation.MediaFeature[] features)
Emulates the given media type or media feature for CSS media queries.- Parameters:
media- Media type to emulate. Empty string disables the override.
OPTIONALfeatures- Media features to emulate.
OPTIONAL- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setEmulatedOSTextScale
public static Script<java.lang.Void> setEmulatedOSTextScale (java.lang.Number scale)
Emulates the given OS text scale.- Parameters:
scale- -
OPTIONAL- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setEmulatedVisionDeficiency
public static Script<java.lang.Void> setEmulatedVisionDeficiency (java.lang.String type)
Emulates the given vision deficiency.- Parameters:
type- Vision deficiency to emulate. Order: best-effort emulations come first, followed by any physiologically accurate emulations for medically recognized color vision deficiencies.
Acceptable Values: ["achromatopsia", "blurredVision", "deuteranopia", "none", "protanopia", "reducedContrast", "tritanopia"]- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setFocusEmulationEnabled
public static Script<java.lang.Void> setFocusEmulationEnabled (boolean enabled)
Enables or disables simulating a focused and active page.
EXPERIMENTAL- Parameters:
enabled- Whether to enable to disable focus emulation.- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setGeolocationOverride
public static Script<java.lang.Void> setGeolocationOverride (java.lang.Number latitude, java.lang.Number longitude, java.lang.Number accuracy, java.lang.Number altitude, java.lang.Number altitudeAccuracy, java.lang.Number heading, java.lang.Number speed)
Overrides the Geolocation Position or Error. Omitting latitude, longitude or accuracy emulates position unavailable.👍 Because of the sheer number of input parameters to this method, there is a aCommandBuildervariant to this method which may be invoked instead.
Please View:setGeolocationOverride()- Parameters:
latitude- Mock latitude
OPTIONALlongitude- Mock longitude
OPTIONALaccuracy- Mock accuracy
OPTIONALaltitude- Mock altitude
OPTIONALaltitudeAccuracy- Mock altitudeAccuracy
OPTIONALheading- Mock heading
OPTIONALspeed- Mock speed
OPTIONAL- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setHardwareConcurrencyOverride
public static Script<java.lang.Void> setHardwareConcurrencyOverride (int hardwareConcurrency)
[No Description Provided by Google]
EXPERIMENTAL- Parameters:
hardwareConcurrency- Hardware concurrency to report- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setIdleOverride
public static Script<java.lang.Void> setIdleOverride (boolean isUserActive, boolean isScreenUnlocked)
Overrides the Idle state.- Parameters:
isUserActive- Mock isUserActiveisScreenUnlocked- Mock isScreenUnlocked- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setLocaleOverride
public static Script<java.lang.Void> setLocaleOverride (java.lang.String locale)
Overrides default host system locale with the specified one.
EXPERIMENTAL- Parameters:
locale- ICU style C locale (e.g. "en_US"). If not specified or empty, disables the override and restores default host system locale.
OPTIONAL- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setNavigatorOverrides
public static Script<java.lang.Void> setNavigatorOverrides (java.lang.String platform)
Overrides value returned by the javascript navigator object.
EXPERIMENTALDEPRECATED- Parameters:
platform- The platform navigator.platform should return.- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setPageScaleFactor
public static Script<java.lang.Void> setPageScaleFactor (java.lang.Number pageScaleFactor)
Sets a specified page scale factor.
EXPERIMENTAL- Parameters:
pageScaleFactor- Page scale factor.- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setPressureDataOverride
public static Script<java.lang.Void> setPressureDataOverride (java.lang.String source, java.lang.String state, java.lang.Number ownContributionEstimate)
Provides a given pressure data set that will be processed and eventually be delivered to PressureObserver users. |source| must have been previously overridden by setPressureSourceOverrideEnabled.
EXPERIMENTAL- Parameters:
source- -state- -ownContributionEstimate- -
OPTIONAL- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setPressureSourceOverrideEnabled
public static Script<java.lang.Void> setPressureSourceOverrideEnabled (boolean enabled, java.lang.String source, Emulation.PressureMetadata metadata)
Overrides a pressure source of a given type, as used by the Compute Pressure API, so that updates to PressureObserver.observe() are provided via setPressureStateOverride instead of being retrieved from platform-provided telemetry data.
EXPERIMENTAL- Parameters:
enabled- -source- -metadata- -
OPTIONAL- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setPressureStateOverride
public static Script<java.lang.Void> setPressureStateOverride (java.lang.String source, java.lang.String state)
TODO: OBSOLETE: To remove when setPressureDataOverride is merged. Provides a given pressure state that will be processed and eventually be delivered to PressureObserver users. |source| must have been previously overridden by setPressureSourceOverrideEnabled.
EXPERIMENTAL- Parameters:
source- -state- -- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setSafeAreaInsetsOverride
public static Script<java.lang.Void> setSafeAreaInsetsOverride (Emulation.SafeAreaInsets insets)
Overrides the values for env(safe-area-inset-*) and env(safe-area-max-inset-*). Unset values will cause the respective variables to be undefined, even if previously overridden.
EXPERIMENTAL- Parameters:
insets- -- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setScriptExecutionDisabled
public static Script<java.lang.Void> setScriptExecutionDisabled (boolean value)
Switches script execution in the page.- Parameters:
value- Whether script execution should be disabled in the page.- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setScrollbarsHidden
public static Script<java.lang.Void> setScrollbarsHidden(boolean hidden)
[No Description Provided by Google]
EXPERIMENTAL- Parameters:
hidden- Whether scrollbars should be always hidden.- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setSensorOverrideEnabled
public static Script<java.lang.Void> setSensorOverrideEnabled (boolean enabled, java.lang.String type, Emulation.SensorMetadata metadata)
Overrides a platform sensor of a given type. If |enabled| is true, calls to Sensor.start() will use a virtual sensor as backend rather than fetching data from a real hardware sensor. Otherwise, existing virtual sensor-backend Sensor objects will fire an error event and new calls to Sensor.start() will attempt to use a real sensor instead.
EXPERIMENTAL- Parameters:
enabled- -type- -metadata- -
OPTIONAL- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setSensorOverrideReadings
public static Script<java.lang.Void> setSensorOverrideReadings (java.lang.String type, Emulation.SensorReading reading)
Updates the sensor readings reported by a sensor type previously overridden by setSensorOverrideEnabled.
EXPERIMENTAL- Parameters:
type- -reading- -- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setSmallViewportHeightDifferenceOverride
public static Script<java.lang.Void> setSmallViewportHeightDifferenceOverride (int difference)
Allows overriding the difference between the small and large viewport sizes, which determine the value of thesvhandlvhunit, respectively. Only supported for top-level frames.
EXPERIMENTAL- Parameters:
difference- This will cause an element of size 100svh to bedifferencepixels smaller than an element of size 100lvh.- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setTimezoneOverride
public static Script<java.lang.Void> setTimezoneOverride (java.lang.String timezoneId)
Overrides default host system timezone with the specified one.- Parameters:
timezoneId- The timezone identifier. List of supported timezones: https://source.chromium.org/chromium/chromium/deps/icu.git/+/faee8bc70570192d82d2978a71e2a615788597d1:source/data/misc/metaZones.txt If empty, disables the override and restores default host system timezone.- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setTouchEmulationEnabled
public static Script<java.lang.Void> setTouchEmulationEnabled (boolean enabled, java.lang.Integer maxTouchPoints)
Enables touch on platforms which do not support them.- Parameters:
enabled- Whether the touch event emulation should be enabled.maxTouchPoints- Maximum touch points supported. Defaults to one.
OPTIONAL- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setUserAgentOverride
public static Script<java.lang.Void> setUserAgentOverride (java.lang.String userAgent, java.lang.String acceptLanguage, java.lang.String platform, Emulation.UserAgentMetadata userAgentMetadata)
Allows overriding user agent with the given string.userAgentMetadatamust be set for Client Hint headers to be sent.- Parameters:
userAgent- User agent to use.acceptLanguage- Browser language to emulate.
OPTIONALplatform- The platform navigator.platform should return.
OPTIONALuserAgentMetadata- To be sent in Sec-CH-UA-* headers and returned in navigator.userAgentData
OPTIONALEXPERIMENTAL- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setVirtualTimePolicy
public static Script<java.lang.Number> setVirtualTimePolicy (java.lang.String policy, java.lang.Number budget, java.lang.Integer maxVirtualTimeTaskStarvationCount, java.lang.Number initialVirtualTime)
Turns on virtual time for all frames (replacing real-time with a synthetic time source) and sets the current virtual time policy. Note this supersedes any previous time budget.
EXPERIMENTAL- Parameters:
policy- -budget- If set, after this many virtual milliseconds have elapsed virtual time will be paused and a virtualTimeBudgetExpired event is sent.
OPTIONALmaxVirtualTimeTaskStarvationCount- If set this specifies the maximum number of tasks that can be run before virtual is forced forwards to prevent deadlock.
OPTIONALinitialVirtualTime- If set, base::Time::Now will be overridden to initially return this value.
OPTIONAL- Returns:
- An instance of
Script<Number>
This script may be executed, usingScript.exec, and afterwards, aPromise<Number>will be returned
Finally, thePromisemay be awaited, usingPromise.await(), and the returned result of this Browser Function may be retrieved.This Browser Function'sPromisereturns:Number (virtualTimeTicksBase)
Absolute timestamp at which virtual time was first enabled (up time in milliseconds).
-
setVisibleSize
public static Script<java.lang.Void> setVisibleSize(int width, int height)
Resizes the frame/viewport of the page. Note that this does not affect the frame's container (e.g. browser window). Can be used to produce screenshots of the specified size. Not supported on Android.
EXPERIMENTALDEPRECATED- Parameters:
width- Frame width (DIP).height- Frame height (DIP).- Returns:
- An instance of
Script<Void>
ThisScriptinstance must be executed before the browser receives the invocation-request.This Browser-Function does not have a return-value. You may choose to await thePromise<Void>to ensure that the Browser Function has run to completion.
-
setDeviceMetricsOverride
public static CommandBuilder<java.lang.Void> setDeviceMetricsOverride()
Creates a buider for conveniently assigning parameters to this method.Note that the original method expects 14 parameters, and can be cumbersome.- Returns:
CommandBuilderinstance, for assigning parameter values, one by one.- See Also:
setDeviceMetricsOverride(int, int, java.lang.Number, boolean, java.lang.Number, java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Boolean, Torello.Browser.BrowserAPI.Emulation.ScreenOrientation, Torello.Browser.BrowserAPI.Page.Viewport, Torello.Browser.BrowserAPI.Emulation.DisplayFeature, Torello.Browser.BrowserAPI.Emulation.DevicePosture)
-
setGeolocationOverride
public static CommandBuilder<java.lang.Void> setGeolocationOverride()
Creates a buider for conveniently assigning parameters to this method.Note that the original method expects 7 parameters, and can be cumbersome.- Returns:
CommandBuilderinstance, for assigning parameter values, one by one.- See Also:
setGeolocationOverride(java.lang.Number, java.lang.Number, java.lang.Number, java.lang.Number, java.lang.Number, java.lang.Number, java.lang.Number)
-
-