Sensors: Emulate device sensors

Kayce Basques
Kayce Basques
Sofia Emelianova
Sofia Emelianova

Use theSensors panel to emulate sensor input of any device.

Overview

TheSensors panel lets you do the following:

Key point: To simulate a viewport of a mobile device and throttle the network and CPU, seeDevice Mode.

Open the Sensors panel

  1. Depending on your operating system, press the following to open the Command Menu:

    • On MacOS,Command+Shift+P
    • On Windows, Linux, or ChromeOS,Control+Shift+P

    Using the Command Menu to open the Sensors panel.

  2. Typesensors, selectShow Sensors, and pressEnter. TheSensors panel opens up at the bottom of your DevTools window.

Override geolocation

Many websites take advantage ofuser location in order to provide a more relevant experience for their users. For example, a weather website might show the local forecast for a user's area, once the user has granted the website permission to access their location.

If you're building a UI that changes depending on where the user is located, you probably want to make sure that the site behaves correctly in different places around the world.

To override your geolocation,open theSensors panel and, from theGeolocation list select one of the following:

  • One of the preset cities, likeTokyo.
  • Custom location to enter custom longitude and latitude coordinates.
  • SelectLocation unavailable to see how your site behaves when the user's location is not available.

Selecting 'Tokyo' from the 'Geolocation' list.

Simulate device orientation

To simulate differentdevice orientations,open theSensors panel, and, from theOrientation list, select one of the following:

  • One of the preset orientations, likePortrait upside down.
  • Custom orientation to provide your own exact orientation.

Selecting 'Portrait upside down' from the 'Orientation' list.

After selectingCustom orientation thealpha,beta, andgamma fields areenabled. SeeAlpha,Beta, andGamma to understand how these axes work.

You can also set a custom orientation by dragging theOrientation Model. HoldShift before dragging to rotate along thealpha axis.

The Orientation Model.

Force touch

To test touch events on your website, you can force touch instead of click even if you're testing on a device without a touch screen.

To trigger touch events with your pointer:

  1. Open theSensors panel.
  2. Under theTouch drop-down list, selectForce touch.Forcing touch instead of click.
  3. ClickReload DevTools in the prompt at the top.

Emulate idle detector state

TheIdle Detection API lets you detect inactive users and react on idle state changes. With DevTools, you can emulate idle state changes for both the user state and screen state instead of waiting for the actual idle state to change.

To emulate idle states:

  1. Open theSensors panel. For this tutorial, you can try it on thisdemo page.

  2. Enable the checkbox next toEphemeral and, in the prompt, grant the demo page the idle detection permission. Then, reload the page.

    Granting the idle detection permission on a demo page.

  3. Under theEmulate Idle detector State drop-down, select one of the following:

    • No idle emulation
    • User active, screen unlocked
    • User active, screen locked
    • User idle, screen unlocked
    • User idle, screen locked

Selecting an idle and locked state on a demo page.

In this example, DevTools emulates anUser idle, screen locked state and, in this case, the demo page starts the 10 second countdown to clear the canvas.

Emulate hardware concurrency

To emulate how your website performs on devices with different numbers of processor cores, you can override the value reported by thenavigator.hardwareConcurrency property. Some applications use this property to control the degree of parallelism of their application, for example, to controlEmscriptenpthread pool size.

To emulate hardware concurrency:

  1. Open theSensors panel.
  2. Near the bottom of the panel, find and turn onHardware concurrency.
  3. In the number input box, enter the number of cores you want to emulate.

Turned on 'Hardware concurrency' with the number of cores set to 10.

Caution: Exceeding the default value of12 may degrade performance.

To revert to the default value, click theReset button.

Emulate CPU pressure

CPU or compute pressure is a set of reported states that give you an idea of how much workload the system's compute is undergoing and whether it's near to the limit or not. This information lets you adapt your real-time application, for example, video conferencing or video game, to take advantage of all the available processing power while keeping the system responsive by adapting the workloads in real time.

TheSensors panel lets you emulate the states that can be reported by theCompute Pressure API.

To emulate CPU pressure on your website:

  1. Open theSensors panel.
  2. Near the bottom of the panel, find theCPU pressure section, and select one of thehuman-readable pressure states:No override,Nominal,Fair,Serious, orCritical.
  3. In the prompt at the top of DevTools, clickReload DevTools.

Emulating 'Serious' CPU pressure.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2020-09-20 UTC.