Class Emulation


  • public class Emulation
    extends java.lang.Object
    Class created by Automatic Code-Generator.
    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.

    JSON-Viewable Google-API:
    These files may be viewed here: browser_protocol.json and js_protocol.json.
    These files were converted into this Java-Browser (CDT) Library; they are a Java-Alternative to the Node.js implementation.

    HTML-Viewable API:
    In addition to this Class-Library, these files were also converted to a simple HTML Page, which may be browsed here: Browser API Web-Page

    Node.js RDP-API Implementation:
    You may read about the Node.js Chrome Remote Interface on the Node.js Package Manager Web-Site: NPM
    This domain emulates different environments for the page.

    This class is intended to be used with a Headless Browser

    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 a Remote Debugging Port. The initializations may be accomplished using class BRDPC (Browser Remote Debug Protocol Connection).

    Google-Chrome was used during the development process of the classes in this particular package. Note that, lately, it has been asserted Microsoft has switched to using the Chrome-Engine for its Microsoft Edge Browser Internal Code-Base. Therefore, there may limited support / functionality when running the methods in this class with Microsoft-Edge. There is the possibility these will work with Opera & Safari.

    Check whether the your Web-Browser will allow itself to be driven by the Web-Socket RDP-Port 9223.


    Foreign Function API:
    Every one of the methods that reside in this class are designed to do nothing more than:

    1. Accept Parameters from the User, and "Marshall Them" into a Valid JSON-Request
    2. Transmit the Marshalled Request-JSON to a Headless Web-Browser over a Web-Socket RDP Connection
    3. Receive BOTH that Method's Results AND any Browser Event-Firings from the Web-Socket
    4. Parse JSON Method-Results and Browser-Event Firings, and Subsequently Convert them to Standard Java-Types
    5. Report these Method-Results and Browser-Events to the User via an User-Registered Event-Listener or a Promise Object


    Java-HTML Difference:
    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".



    Stateless Class:
    This class neither contains any program-state, nor can it be instantiated. The @StaticFunctional Annotation may also be called 'The Spaghetti Report'. Static-Functional classes are, essentially, C-Styled Files, without any constructors or non-static member fields. It is a concept very similar to the Java-Bean's @Stateless Annotation.

    • 1 Constructor(s), 1 declared private, zero-argument constructor
    • 27 Method(s), 27 declared static
    • 7 Field(s), 7 declared static, 6 declared final
    • Fields excused from final modifier (with explanation):
      Field 'counter' is not final. Reason: CONFIGURATION


    • Field Detail

      • VirtualTimePolicy

        🡅  🡇     🗕  🗗  🗖
        public static final 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
    • Method Detail

      • canEmulate

        🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​java.lang.Boolean> canEmulate
                    ()
        
        Tells whether emulation is supported.
        Returns:
        An instance of Script<String, JsonObject, Boolean>

        This script may be executed, using Script.exec(), and afterwards, a Promise<JsonObject, Boolean> will be returned.

        Finally, the Promise may be awaited, using Promise.await(), and the returned result of this Browser Function may may be retrieved.

        This Browser Function returns

        • Boolean (result)
          True if emulation is supported.
      • clearGeolocationOverride

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0clearGeolocationOverride
                    ()
        
        Clears the overridden Geolocation Position and Error.
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • resetPageScaleFactor

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0resetPageScaleFactor
                    ()
        
        Requests that page scale factor is reset to initial values.
        EXPERIMENTAL
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setFocusEmulationEnabled

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setFocusEmulationEnabled​
                    (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<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setAutoDarkModeOverride

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setAutoDarkModeOverride​
                    (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<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setCPUThrottlingRate

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setCPUThrottlingRate​
                    (java.lang.Number rate)
        
        Enables CPU throttling to emulate slow CPUs.
        EXPERIMENTAL
        Parameters:
        rate - Throttling rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc).
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setDefaultBackgroundColorOverride

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setDefaultBackgroundColorOverride​
                    (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<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setDeviceMetricsOverride

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setDeviceMetricsOverride​
                    (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)
        
        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).
        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.
        OPTIONAL
        EXPERIMENTAL
        screenWidth - Overriding screen width value in pixels (minimum 0, maximum 10000000).
        OPTIONAL
        EXPERIMENTAL
        screenHeight - Overriding screen height value in pixels (minimum 0, maximum 10000000).
        OPTIONAL
        EXPERIMENTAL
        positionX - Overriding view X position on screen in pixels (minimum 0, maximum 10000000).
        OPTIONAL
        EXPERIMENTAL
        positionY - Overriding view Y position on screen in pixels (minimum 0, maximum 10000000).
        OPTIONAL
        EXPERIMENTAL
        dontSetVisibleSize - Do not set visible view size, rely upon explicit setVisibleSize call.
        OPTIONAL
        EXPERIMENTAL
        screenOrientation - Screen orientation override.
        OPTIONAL
        viewport - 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.
        OPTIONAL
        EXPERIMENTAL
        displayFeature - If set, the display feature of a multi-segment screen. If not set, multi-segment support is turned-off.
        OPTIONAL
        EXPERIMENTAL
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setScrollbarsHidden

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setScrollbarsHidden​
                    (boolean hidden)
        
        [No Description Provided by Google]
        EXPERIMENTAL
        Parameters:
        hidden - Whether scrollbars should be always hidden.
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setDocumentCookieDisabled

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setDocumentCookieDisabled​
                    (boolean disabled)
        
        [No Description Provided by Google]
        EXPERIMENTAL
        Parameters:
        disabled - Whether document.coookie API should be disabled.
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setEmitTouchEventsForMouse

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setEmitTouchEventsForMouse​
                    (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: ["mobile", "desktop"]
        OPTIONAL
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setEmulatedMedia

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setEmulatedMedia​
                    (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.
        OPTIONAL
        features - Media features to emulate.
        OPTIONAL
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setEmulatedVisionDeficiency

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setEmulatedVisionDeficiency​
                    (java.lang.String type)
        
        Emulates the given vision deficiency.
        EXPERIMENTAL
        Parameters:
        type - Vision deficiency to emulate.
        Acceptable Values: ["none", "achromatopsia", "blurredVision", "deuteranopia", "protanopia", "tritanopia"]
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setGeolocationOverride

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setGeolocationOverride​
                    (java.lang.Number latitude,
                     java.lang.Number longitude,
                     java.lang.Number accuracy)
        
        Overrides the Geolocation Position or Error. Omitting any of the parameters emulates position unavailable.
        Parameters:
        latitude - Mock latitude
        OPTIONAL
        longitude - Mock longitude
        OPTIONAL
        accuracy - Mock accuracy
        OPTIONAL
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setIdleOverride

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setIdleOverride​
                    (boolean isUserActive,
                     boolean isScreenUnlocked)
        
        Overrides the Idle state.
        EXPERIMENTAL
        Parameters:
        isUserActive - Mock isUserActive
        isScreenUnlocked - Mock isScreenUnlocked
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • clearIdleOverride

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0clearIdleOverride
                    ()
        
        Clears Idle state overrides.
        EXPERIMENTAL
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setNavigatorOverrides

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setNavigatorOverrides​
                    (java.lang.String platform)
        
        Overrides value returned by the javascript navigator object.
        EXPERIMENTAL
        DEPRECATED
        Parameters:
        platform - The platform navigator.platform should return.
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setPageScaleFactor

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setPageScaleFactor​
                    (java.lang.Number pageScaleFactor)
        
        Sets a specified page scale factor.
        EXPERIMENTAL
        Parameters:
        pageScaleFactor - Page scale factor.
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setScriptExecutionDisabled

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setScriptExecutionDisabled​
                    (boolean value)
        
        Switches script execution in the page.
        Parameters:
        value - Whether script execution should be disabled in the page.
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setTouchEmulationEnabled

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setTouchEmulationEnabled​
                    (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<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setVirtualTimePolicy

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​java.lang.Number> setVirtualTimePolicy​
                    (java.lang.String policy,
                     java.lang.Number budget,
                     java.lang.Integer maxVirtualTimeTaskStarvationCount,
                     java.lang.Boolean waitForNavigation,
                     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.
        OPTIONAL
        maxVirtualTimeTaskStarvationCount - If set this specifies the maximum number of tasks that can be run before virtual is forced forwards to prevent deadlock.
        OPTIONAL
        waitForNavigation - If set the virtual time policy change should be deferred until any frame starts navigating. Note any previous deferred policy change is superseded.
        OPTIONAL
        initialVirtualTime - If set, base::Time::Now will be overridden to initially return this value.
        OPTIONAL
        Returns:
        An instance of Script<String, JsonObject, Number>

        This script may be executed, using Script.exec(), and afterwards, a Promise<JsonObject, Number> will be returned.

        Finally, the Promise may be awaited, using Promise.await(), and the returned result of this Browser Function may may be retrieved.

        This Browser Function returns

        • Number (virtualTimeTicksBase)
          Absolute timestamp at which virtual time was first enabled (up time in milliseconds).
      • setLocaleOverride

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setLocaleOverride​
                    (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<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setTimezoneOverride

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setTimezoneOverride​
                    (java.lang.String timezoneId)
        
        Overrides default host system timezone with the specified one.
        EXPERIMENTAL
        Parameters:
        timezoneId - The timezone identifier. If empty, disables the override and restores default host system timezone.
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setVisibleSize

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setVisibleSize​
                    (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.
        EXPERIMENTAL
        DEPRECATED
        Parameters:
        width - Frame width (DIP).
        height - Frame height (DIP).
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setDisabledImageTypes

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setDisabledImageTypes​
                    (java.lang.String[] imageTypes)
        
        [No Description Provided by Google]
        EXPERIMENTAL
        Parameters:
        imageTypes - Image types to disable.
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.
      • setUserAgentOverride

        🡅  🡇     🗕  🗗  🗖
        public static Script<java.lang.String,​JsonObject,​Ret0setUserAgentOverride​
                    (java.lang.String userAgent,
                     java.lang.String acceptLanguage,
                     java.lang.String platform,
                     Emulation.UserAgentMetadata userAgentMetadata)
        
        Allows overriding user agent with the given string.
        Parameters:
        userAgent - User agent to use.
        acceptLanguage - Browser langugage to emulate.
        OPTIONAL
        platform - The platform navigator.platform should return.
        OPTIONAL
        userAgentMetadata - To be sent in Sec-CH-UA-* headers and returned in navigator.userAgentData
        OPTIONAL
        EXPERIMENTAL
        Returns:
        An instance of Script<String, JsonObject, Ret0>

        This Script instance must be executed before the browser receives the invocation-request.

        This Browser-Function does not have a return-value. You may choose to await the Promise<JsonObject, Ret0 > to ensure the Browser Function has run to completion.