Emulate mobile devices (Device Emulation)
Use the Device Emulation tool, sometimes called Device Mode, to approximate how your page looks and responds on a mobile device.
DevTools provides the following mobile device emulation features:
- Simulate a mobile viewport
- Throttle the network
- Throttle the CPU
- Override geolocation
- Set orientation
- Set the user agent string
- Set user-agent client hints
Limitations
Device Emulation is a first-order approximation of the look and feel of your page on a mobile device. Device Emulation doesn't actually run your code on a mobile device. Instead, you simulate the mobile user experience from your laptop or desktop.
Some aspects of mobile devices are never emulated in DevTools. For example, the architecture of mobile CPUs is different than the architecture of laptop or desktop CPUs. When in doubt, your best bet is to actually run your page on a mobile device.
Use Remote Debugging to interact with the code of a page from your machine while your page actually runs on a mobile device. You can view, change, debug, profile, or all four while you interact with the code. Your machine can be a notebook or desktop computer.
Simulate a mobile viewport
Select Toggle device emulation () or select Customize and control DevTools (
...
) > Device Emulation to open the UI that enables you to simulate a mobile viewport.
By default the Device Toolbar opens in Responsive Viewport Mode.
Responsive Viewport Mode
To quickly test the look and feel of your page across multiple screen sizes, drag the handles to resize the viewport to your required dimensions. You can enter any numeric values in the width and height boxes. If you select a size larger than available in the browser window, the viewport will be automatically scaled to accommodate for the larger viewport.
In the following figure, the width is set to 626
and the height is set to 516
.
If you need more space on your screen, you can always change the position of DevTools as explained in Change DevTools placement (Undock, Dock to bottom, Dock to left).
Show media queries
If you have defined media queries on your page, jump to the viewport dimensions where those media queries take effect by showing media query breakpoints above your viewport. Select More options > Show media queries.
Select a breakpoint to change the width of the viewport so that the media query gets triggered.
Set the device type
Use the Device Type list to simulate a mobile device or desktop device.
The following table describes the differences between the available device type options. The Rendering method column refers to whether Microsoft Edge renders the page as a mobile or desktop viewport. The Cursor icon column refers to what type of cursor is displayed when you hover on the page. The Events triggered column refers to whether the page triggers touch
or click
events when you interact with the page.
Option | Rendering method | Cursor icon | Events triggered |
---|---|---|---|
Mobile | Mobile | Circle | touch |
Mobile (no touch) | Mobile | Normal | click |
Desktop | Desktop | Normal | click |
Desktop (touch) | Desktop | Circle | touch |
Note
If the Device Type list isn't displayed, select More options > Add device type.
Mobile Device Viewport Mode
To simulate the dimensions of a specific mobile device, select the device from the Device list.
Rotate the viewport to landscape orientation
Test your webpage in landscape orientation.
To rotate the viewport to landscape orientation, select Rotate (
):
The Rotate button disappears if your Device Toolbar is narrow.
If needed, to access the Rotate button, increase the width of the Device Toolbar.
See also Set orientation, below.
Show device frame
To simulate the dimensions of a specific mobile device, open More options and then select Show device frame to show the physical device frame around the viewport.
If a device frame isn't shown for a particular device, it means that DevTools doesn't have art for that device.
The device frame for the iPhone 6:
Add a custom mobile device
If the mobile device option that you need isn't included on the default list, you can add a custom device. To add a custom device:
Select the Device list > Edit.
Select Add custom device.
On Emulated Devices, enter a device name, screen width, and screen height for the custom device. The device pixel ratio, user agent string, and device type fields are optional. The device type field defaults to Mobile.
Show rulers
If you need to measure screen dimensions, you can use rulers to measure the screen size in pixels. Select More options > Show rulers to display rulers above and to the left of your viewport.
Rulers appear above and to the left of the viewport:
Zoom the viewport
To test the look and feel of your page at multiple zoom levels, use the Zoom list to zoom in or out.
Throttle the network and CPU
Mobile devices often have network and CPU constraints. Test how quickly your page loads and how it responds at different internet and CPU speeds.
Select Throttle list and change the preset to Mid-tier mobile or Low-end mobile.
- Mid-tier mobile simulates
fast 3G
and throttles your CPU. It is four times slower than normal. - Low-end mobile simulates
slow 3G
and throttles your CPU. It is six times slower than normal.
All of the throttling is based upon the normal capability of your laptop or desktop.
If the Throttle list is hidden, your Device Toolbar is too narrow.
- Mid-tier mobile simulates
If needed, to access the Throttle list, increase the width of the Device Toolbar.
Throttle the CPU only
To throttle the CPU only and not the network:
Select the Performance panel, and select Capture Settings (
).
Select CPU > 4x slowdown or 6x slowdown.
Throttle the network only
To throttle the network only and not the CPU:
Select the Network tool, then select Online > Fast 3G or Slow 3G.
Or, press Ctrl+Shift+P (Windows, Linux) or Command+Shift+P (macOS) to open the Command Menu, start typing
3g
, and then select Enable fast 3G throttling or Enable slow 3G throttling.
You can also set network throttling from the Performance panel:
Select Capture Settings (
) and select the Network list and change the preset to Fast 3G or Slow 3G.
Override geolocation
If your page depends on geolocation information from a mobile device to render properly, provide different geolocations using the geolocation-overriding UI.
Select Customize and control DevTools (
...
) > More tools > Sensors.Or, open the Command Menu by selecting Ctrl+Shift+P (Windows, Linux) or Command+Shift+P (macOS). Type
Sensors
and then select Show Sensors.
On the Sensors panel, to select one of the preset locations, use the Location dropdown menu. To enter a custom location, select Other and enter the coordinates of your custom location. To test how your page behaves when location information is unavailable, select Location unavailable.
Set orientation
If your page depends on orientation information from a mobile device to render properly, open the orientation UI.
Select Customize and control DevTools (
...
) > More tools > Sensors.Or, open the Command Menu by pressing Ctrl+Shift+P (Windows, Linux) or Command+Shift+P (macOS). Type
Sensors
, and then select Show Sensors.On the Sensors panel, you can select a preset orientation from the Orientation dropdown menu.
To enter your own orientation, select Custom orientation, and enter your own alpha, beta, and gamma values.
Set the user agent string
If your page depends on the user agent string from a mobile device to render properly, use the Network conditions panel to provide different user agent strings.
Select Customize and control DevTools (
...
) > More tools > Network conditions.Or, open the Command Menu by pressing Ctrl+Shift+P (Windows, Linux) or Command+Shift+P (macOS).Type
Network conditions
, and select Show Network conditions.Next to User agent, clear the Use browser default checkbox.
Select Custom to select from a list of predefined user agent strings.
To enter your own user agent string, enter the string in Enter a custom user agent.
See also
Set user-agent client hints
If your site employs user-agent client hints, use the Emulated Devices panel to add devices and set user-agent client hints.
Right-click in a webpage and then select Inspect.
Select Settings > Devices.
In the Emulated Devices panel, select Add custom device and expand user-agent client hints.
Type a unique name in the Device Name text box such as
Test101
.Accept the default values or change Width, Height, and Device pixel ratio as needed.
Set user-agent client hints as follows:
- Brand and Version, such as Edge and 92. Select + Add Brand to add multiple brand and version pairs.
- Full Browser Version such as 92.0.1111.0.
- Platform and Version such as Windows and 10.0.
- Architecture such as x86.
- Device model such as Galaxy Nexus.
You can set or change any of the user-agent client hints. There are no required values.
Click Add. The new device is displayed in the selected state at the top of the Emulated Devices list.
You can also set user-agent client hints in the Network tool; see Network features reference.
Note
Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons Attribution 4.0 International License. The original page is found here and is authored by Kayce Basques (Technical Writer, Chrome DevTools & Lighthouse).
This work is licensed under a Creative Commons Attribution 4.0 International License.
Váš názor
Odeslat a zobrazit názory pro