Class ExtendedClientDetails

java.lang.Object
com.vaadin.flow.component.page.ExtendedClientDetails
All Implemented Interfaces:
Serializable

public class ExtendedClientDetails extends Object implements Serializable
Provides extended information about the web browser, such as screen resolution and time zone.

Please note that all information is fetched only once, and not updated automatically. To retrieve updated values, you can execute JS with Page.executeJs(String, Serializable...) and get the current value back.

Since:
2.0
Author:
Vaadin Ltd
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the height of the body element in the document in pixels.
    int
    Gets the width of the body element in the document in pixels.
    Returns the current date and time of the browser.
    double
    Gets the device pixel ratio, window.devicePixelRatio.
    int
    Returns the offset in milliseconds between the browser's GMT TimeZone and DST.
    int
    Returns the browser-reported TimeZone offset in milliseconds from GMT ignoring possible daylight saving adjustments that may be in effect in the browser.
    int
    Gets the height of the screen in pixels.
    int
    Gets the width of the screen in pixels.
    Returns the TimeZone Id (like "Europe/Helsinki") provided by the browser (if the browser supports this feature).
    int
    Returns the browser-reported TimeZone offset in milliseconds from GMT.
    int
    Gets the inner height of the browser window window.innerHeight in pixels.
    int
    Gets the inner width of the browser window window.innerWidth in pixels.
    Returns a unique browser window identifier.
    boolean
    Returns whether daylight saving time (DST) is currently in effect in the region of the browser or not.
    boolean
    Check if the browser is run on IOS.
    boolean
    Check if the browser is run on IPad.
    boolean
    Checks if the browser supports touch events.

    Methods inherited from class java.lang.Object

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

    • getScreenWidth

      public int getScreenWidth()
      Gets the width of the screen in pixels. This is the full screen resolution and not the width available for the application.
      Returns:
      the width of the screen in pixels.
    • getScreenHeight

      public int getScreenHeight()
      Gets the height of the screen in pixels. This is the full screen resolution and not the height available for the application.
      Returns:
      the height of the screen in pixels.
    • getWindowInnerHeight

      public int getWindowInnerHeight()
      Gets the inner height of the browser window window.innerHeight in pixels. This includes the scrollbar, if it is visible.
      Returns:
      the browser window inner height in pixels
    • getWindowInnerWidth

      public int getWindowInnerWidth()
      Gets the inner width of the browser window window.innerWidth in pixels. This includes the scrollbar, if it is visible.
      Returns:
      the browser window inner width in pixels
    • getBodyClientHeight

      public int getBodyClientHeight()
      Gets the height of the body element in the document in pixels.
      Returns:
      the height of the body element
    • getBodyClientWidth

      public int getBodyClientWidth()
      Gets the width of the body element in the document in pixels.
      Returns:
      the width of the body element
    • getTimezoneOffset

      public int getTimezoneOffset()
      Returns the browser-reported TimeZone offset in milliseconds from GMT. This includes possible daylight saving adjustments, to figure out which TimeZone the user actually might be in, see getRawTimezoneOffset().
      Returns:
      timezone offset in milliseconds, 0 if not available
      See Also:
    • getTimeZoneId

      public String getTimeZoneId()
      Returns the TimeZone Id (like "Europe/Helsinki") provided by the browser (if the browser supports this feature).
      Returns:
      the TimeZone Id if provided by the browser, null otherwise.
      See Also:
    • getRawTimezoneOffset

      public int getRawTimezoneOffset()
      Returns the browser-reported TimeZone offset in milliseconds from GMT ignoring possible daylight saving adjustments that may be in effect in the browser.

      You can use this to figure out which TimeZones the user could actually be in by calling TimeZone.getAvailableIDs(int).

      If getRawTimezoneOffset() and getTimezoneOffset() returns the same value, the browser is either in a zone that does not currently have daylight saving time, or in a zone that never has daylight saving time.

      Returns:
      timezone offset in milliseconds excluding DST, 0 if not available
    • getDSTSavings

      public int getDSTSavings()
      Returns the offset in milliseconds between the browser's GMT TimeZone and DST.
      Returns:
      the number of milliseconds that the TimeZone shifts when DST is in effect
    • isDSTInEffect

      public boolean isDSTInEffect()
      Returns whether daylight saving time (DST) is currently in effect in the region of the browser or not.
      Returns:
      true if the browser resides at a location that currently is in DST
    • getCurrentDate

      public Date getCurrentDate()
      Returns the current date and time of the browser. This will not be entirely accurate due to varying network latencies, but should provide a close-enough value for most cases. Also note that the returned Date object uses servers default time zone, not the clients.

      To get the actual date and time shown in the end users computer, you can do something like:

       WebBrowser browser = ...;
       SimpleTimeZone timeZone = new SimpleTimeZone(browser.getTimezoneOffset(), "Fake client time zone");
       DateFormat format = DateFormat.getDateTimeInstance();
       format.setTimeZone(timeZone);
       myLabel.setValue(format.format(browser.getCurrentDate()));
       
      Returns:
      the current date and time of the browser.
      See Also:
    • isTouchDevice

      public boolean isTouchDevice()
      Checks if the browser supports touch events.
      Returns:
      true if the browser is detected to support touch events, false otherwise
    • getDevicePixelRatio

      public double getDevicePixelRatio()
      Gets the device pixel ratio, window.devicePixelRatio. See more from MDN web docs.

      A value of -1 indicates that the value was not reported by the browser correctly.

      Returns:
      double-precision floating-point value indicating the ratio of the display's resolution in physical pixels to the resolution in CSS pixels
    • getWindowName

      public String getWindowName()
      Returns a unique browser window identifier. For internal use only.
      Returns:
      An id which persists if the UI is reloaded in the same browser window/tab.
    • isIPad

      public boolean isIPad()
      Check if the browser is run on IPad.
      Returns:
      true if run on IPad false if the user is not using IPad or if no information from the browser is present
    • isIOS

      public boolean isIOS()
      Check if the browser is run on IOS.
      Returns:
      true if run on IOS , false if the user is not using IOS or if no information from the browser is present