Class EmulationImpl

java.lang.Object
io.webfolder.cdp.command.EmulationImpl
All Implemented Interfaces:
Emulation

public class EmulationImpl
extends java.lang.Object
implements Emulation
  • Constructor Summary

    Constructors 
    Constructor Description
    EmulationImpl​(SessionInvocationHandler handler)  
  • Method Summary

    Modifier and Type Method Description
    java.lang.Boolean canEmulate()
    Tells whether emulation is supported.
    void clearDeviceMetricsOverride()
    Clears the overriden device metrics.
    void clearGeolocationOverride()
    Clears the overriden Geolocation Position and Error.
    void resetPageScaleFactor()
    Requests that page scale factor is reset to initial values.
    void setCPUThrottlingRate​(java.lang.Double rate)
    Enables CPU throttling to emulate slow CPUs.
    void setDefaultBackgroundColorOverride()
    Sets or clears an override of the default background color of the frame.
    void setDefaultBackgroundColorOverride​(RGBA color)
    Sets or clears an override of the default background color of the frame.
    void setDeviceMetricsOverride​(java.lang.Integer width, java.lang.Integer height, java.lang.Double deviceScaleFactor, java.lang.Boolean mobile)
    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).
    void setDeviceMetricsOverride​(java.lang.Integer width, java.lang.Integer height, java.lang.Double deviceScaleFactor, java.lang.Boolean mobile, java.lang.Double scale, java.lang.Integer screenWidth, java.lang.Integer screenHeight, java.lang.Integer positionX, java.lang.Integer positionY, java.lang.Boolean dontSetVisibleSize, ScreenOrientation screenOrientation, Viewport viewport)
    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).
    void setDocumentCookieDisabled​(java.lang.Boolean disabled)  
    void setEmitTouchEventsForMouse​(java.lang.Boolean enabled)  
    void setEmitTouchEventsForMouse​(java.lang.Boolean enabled, Platform configuration)  
    void setEmulatedMedia()
    Emulates the given media type or media feature for CSS media queries.
    void setEmulatedMedia​(java.lang.String media, java.util.List<MediaFeature> features)
    Emulates the given media type or media feature for CSS media queries.
    void setFocusEmulationEnabled​(java.lang.Boolean enabled)
    Enables or disables simulating a focused and active page.
    void setGeolocationOverride()
    Overrides the Geolocation Position or Error.
    void setGeolocationOverride​(java.lang.Double latitude, java.lang.Double longitude, java.lang.Double accuracy)
    Overrides the Geolocation Position or Error.
    void setNavigatorOverrides​(java.lang.String platform)
    Overrides value returned by the javascript navigator object.
    void setPageScaleFactor​(java.lang.Double pageScaleFactor)
    Sets a specified page scale factor.
    void setScriptExecutionDisabled​(java.lang.Boolean value)
    Switches script execution in the page.
    void setScrollbarsHidden​(java.lang.Boolean hidden)  
    void setTimezoneOverride​(java.lang.String timezoneId)
    Overrides default host system timezone with the specified one.
    void setTouchEmulationEnabled​(java.lang.Boolean enabled)
    Enables touch on platforms which do not support them.
    void setTouchEmulationEnabled​(java.lang.Boolean enabled, java.lang.Integer maxTouchPoints)
    Enables touch on platforms which do not support them.
    void setUserAgentOverride​(java.lang.String userAgent)
    Allows overriding user agent with the given string.
    void setUserAgentOverride​(java.lang.String userAgent, java.lang.String acceptLanguage, java.lang.String platform)
    Allows overriding user agent with the given string.
    java.lang.Double setVirtualTimePolicy​(VirtualTimePolicy policy)
    Turns on virtual time for all frames (replacing real-time with a synthetic time source) and sets the current virtual time policy.
    java.lang.Double setVirtualTimePolicy​(VirtualTimePolicy policy, java.lang.Double budget, java.lang.Integer maxVirtualTimeTaskStarvationCount, java.lang.Boolean waitForNavigation, java.lang.Double initialVirtualTime)
    Turns on virtual time for all frames (replacing real-time with a synthetic time source) and sets the current virtual time policy.
    void setVisibleSize​(java.lang.Integer width, java.lang.Integer height)
    Resizes the frame/viewport of the page.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • canEmulate

      public java.lang.Boolean canEmulate()
      Description copied from interface: Emulation
      Tells whether emulation is supported.
      Specified by:
      canEmulate in interface Emulation
      Returns:
      True if emulation is supported.
    • clearDeviceMetricsOverride

      public void clearDeviceMetricsOverride()
      Description copied from interface: Emulation
      Clears the overriden device metrics.
      Specified by:
      clearDeviceMetricsOverride in interface Emulation
    • clearGeolocationOverride

      public void clearGeolocationOverride()
      Description copied from interface: Emulation
      Clears the overriden Geolocation Position and Error.
      Specified by:
      clearGeolocationOverride in interface Emulation
    • resetPageScaleFactor

      public void resetPageScaleFactor()
      Description copied from interface: Emulation
      Requests that page scale factor is reset to initial values.
      Specified by:
      resetPageScaleFactor in interface Emulation
    • setFocusEmulationEnabled

      public void setFocusEmulationEnabled​(java.lang.Boolean enabled)
      Description copied from interface: Emulation
      Enables or disables simulating a focused and active page.
      Specified by:
      setFocusEmulationEnabled in interface Emulation
      Parameters:
      enabled - Whether to enable to disable focus emulation.
    • setCPUThrottlingRate

      public void setCPUThrottlingRate​(java.lang.Double rate)
      Description copied from interface: Emulation
      Enables CPU throttling to emulate slow CPUs.
      Specified by:
      setCPUThrottlingRate in interface Emulation
      Parameters:
      rate - Throttling rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc).
    • setDefaultBackgroundColorOverride

      public void setDefaultBackgroundColorOverride​(RGBA color)
      Description copied from interface: Emulation
      Sets or clears an override of the default background color of the frame. This override is used if the content does not specify one.
      Specified by:
      setDefaultBackgroundColorOverride in interface Emulation
      Parameters:
      color - RGBA of the default background color. If not specified, any existing override will be cleared.
    • setDeviceMetricsOverride

      public void setDeviceMetricsOverride​(java.lang.Integer width, java.lang.Integer height, java.lang.Double deviceScaleFactor, java.lang.Boolean mobile, java.lang.Double scale, java.lang.Integer screenWidth, java.lang.Integer screenHeight, java.lang.Integer positionX, java.lang.Integer positionY, java.lang.Boolean dontSetVisibleSize, ScreenOrientation screenOrientation, Viewport viewport)
      Description copied from interface: Emulation
      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).
      Specified by:
      setDeviceMetricsOverride in interface Emulation
      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.
      screenWidth - Overriding screen width value in pixels (minimum 0, maximum 10000000).
      screenHeight - Overriding screen height value in pixels (minimum 0, maximum 10000000).
      positionX - Overriding view X position on screen in pixels (minimum 0, maximum 10000000).
      positionY - Overriding view Y position on screen in pixels (minimum 0, maximum 10000000).
      dontSetVisibleSize - Do not set visible view size, rely upon explicit setVisibleSize call.
      screenOrientation - Screen orientation override.
      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.
    • setScrollbarsHidden

      public void setScrollbarsHidden​(java.lang.Boolean hidden)
      Specified by:
      setScrollbarsHidden in interface Emulation
    • setDocumentCookieDisabled

      public void setDocumentCookieDisabled​(java.lang.Boolean disabled)
      Specified by:
      setDocumentCookieDisabled in interface Emulation
    • setEmitTouchEventsForMouse

      public void setEmitTouchEventsForMouse​(java.lang.Boolean enabled, Platform configuration)
      Specified by:
      setEmitTouchEventsForMouse in interface Emulation
    • setEmulatedMedia

      public void setEmulatedMedia​(java.lang.String media, java.util.List<MediaFeature> features)
      Description copied from interface: Emulation
      Emulates the given media type or media feature for CSS media queries.
      Specified by:
      setEmulatedMedia in interface Emulation
      Parameters:
      media - Media type to emulate. Empty string disables the override.
      features - Media features to emulate.
    • setGeolocationOverride

      public void setGeolocationOverride​(java.lang.Double latitude, java.lang.Double longitude, java.lang.Double accuracy)
      Description copied from interface: Emulation
      Overrides the Geolocation Position or Error. Omitting any of the parameters emulates position unavailable.
      Specified by:
      setGeolocationOverride in interface Emulation
      Parameters:
      latitude - Mock latitude
      longitude - Mock longitude
      accuracy - Mock accuracy
    • setNavigatorOverrides

      public void setNavigatorOverrides​(java.lang.String platform)
      Description copied from interface: Emulation
      Overrides value returned by the javascript navigator object.
      Specified by:
      setNavigatorOverrides in interface Emulation
      Parameters:
      platform - The platform navigator.platform should return.
    • setPageScaleFactor

      public void setPageScaleFactor​(java.lang.Double pageScaleFactor)
      Description copied from interface: Emulation
      Sets a specified page scale factor.
      Specified by:
      setPageScaleFactor in interface Emulation
      Parameters:
      pageScaleFactor - Page scale factor.
    • setScriptExecutionDisabled

      public void setScriptExecutionDisabled​(java.lang.Boolean value)
      Description copied from interface: Emulation
      Switches script execution in the page.
      Specified by:
      setScriptExecutionDisabled in interface Emulation
      Parameters:
      value - Whether script execution should be disabled in the page.
    • setTouchEmulationEnabled

      public void setTouchEmulationEnabled​(java.lang.Boolean enabled, java.lang.Integer maxTouchPoints)
      Description copied from interface: Emulation
      Enables touch on platforms which do not support them.
      Specified by:
      setTouchEmulationEnabled in interface Emulation
      Parameters:
      enabled - Whether the touch event emulation should be enabled.
      maxTouchPoints - Maximum touch points supported. Defaults to one.
    • setVirtualTimePolicy

      public java.lang.Double setVirtualTimePolicy​(VirtualTimePolicy policy, java.lang.Double budget, java.lang.Integer maxVirtualTimeTaskStarvationCount, java.lang.Boolean waitForNavigation, java.lang.Double initialVirtualTime)
      Description copied from interface: Emulation
      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.
      Specified by:
      setVirtualTimePolicy in interface Emulation
      budget - If set, after this many virtual milliseconds have elapsed virtual time will be paused and a virtualTimeBudgetExpired event is sent.
      maxVirtualTimeTaskStarvationCount - If set this specifies the maximum number of tasks that can be run before virtual is forced forwards to prevent deadlock.
      waitForNavigation - If set the virtual time policy change should be deferred until any frame starts navigating. Note any previous deferred policy change is superseded.
      initialVirtualTime - If set, base::Time::Now will be overriden to initially return this value.
      Returns:
      Absolute timestamp at which virtual time was first enabled (up time in milliseconds).
    • setTimezoneOverride

      public void setTimezoneOverride​(java.lang.String timezoneId)
      Description copied from interface: Emulation
      Overrides default host system timezone with the specified one.
      Specified by:
      setTimezoneOverride in interface Emulation
      Parameters:
      timezoneId - The timezone identifier. If empty, disables the override and restores default host system timezone.
    • setVisibleSize

      public void setVisibleSize​(java.lang.Integer width, java.lang.Integer height)
      Description copied from interface: Emulation
      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.
      Specified by:
      setVisibleSize in interface Emulation
      Parameters:
      width - Frame width (DIP).
      height - Frame height (DIP).
    • setUserAgentOverride

      public void setUserAgentOverride​(java.lang.String userAgent, java.lang.String acceptLanguage, java.lang.String platform)
      Description copied from interface: Emulation
      Allows overriding user agent with the given string.
      Specified by:
      setUserAgentOverride in interface Emulation
      Parameters:
      userAgent - User agent to use.
      acceptLanguage - Browser langugage to emulate.
      platform - The platform navigator.platform should return.
    • setDefaultBackgroundColorOverride

      public void setDefaultBackgroundColorOverride()
      Description copied from interface: Emulation
      Sets or clears an override of the default background color of the frame. This override is used if the content does not specify one.
      Specified by:
      setDefaultBackgroundColorOverride in interface Emulation
    • setDeviceMetricsOverride

      public void setDeviceMetricsOverride​(java.lang.Integer width, java.lang.Integer height, java.lang.Double deviceScaleFactor, java.lang.Boolean mobile)
      Description copied from interface: Emulation
      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).
      Specified by:
      setDeviceMetricsOverride in interface Emulation
      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.
    • setEmitTouchEventsForMouse

      public void setEmitTouchEventsForMouse​(java.lang.Boolean enabled)
      Specified by:
      setEmitTouchEventsForMouse in interface Emulation
    • setEmulatedMedia

      public void setEmulatedMedia()
      Description copied from interface: Emulation
      Emulates the given media type or media feature for CSS media queries.
      Specified by:
      setEmulatedMedia in interface Emulation
    • setGeolocationOverride

      public void setGeolocationOverride()
      Description copied from interface: Emulation
      Overrides the Geolocation Position or Error. Omitting any of the parameters emulates position unavailable.
      Specified by:
      setGeolocationOverride in interface Emulation
    • setTouchEmulationEnabled

      public void setTouchEmulationEnabled​(java.lang.Boolean enabled)
      Description copied from interface: Emulation
      Enables touch on platforms which do not support them.
      Specified by:
      setTouchEmulationEnabled in interface Emulation
      Parameters:
      enabled - Whether the touch event emulation should be enabled.
    • setVirtualTimePolicy

      public java.lang.Double setVirtualTimePolicy​(VirtualTimePolicy policy)
      Description copied from interface: Emulation
      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.
      Specified by:
      setVirtualTimePolicy in interface Emulation
      Returns:
      Absolute timestamp at which virtual time was first enabled (up time in milliseconds).
    • setUserAgentOverride

      public void setUserAgentOverride​(java.lang.String userAgent)
      Description copied from interface: Emulation
      Allows overriding user agent with the given string.
      Specified by:
      setUserAgentOverride in interface Emulation
      Parameters:
      userAgent - User agent to use.