Note: Some of our documentation may be ahead of the stable version of Chrome. If you are unable to locate a feature listed, we recommend trying Chrome Canary which contains the latest version of the DevTools.
Touch is an input method that's difficult to test on the desktop, since most desktops don't have touch input. Having to test on mobile can lengthen your development cycle, since every change you make needs to be pushed out to a server and then loaded on the device.
A solution to this problem is to simulate touch events on your development machine. For single-touches, the Chrome DevTools supports single touch event emulation to make it easier to debug mobile applications on the desktop.
To enable support for touch event emulation:(使chrome支持触摸事件仿真)
Your mouse actions will now also trigger the relevant touch events: touchstart
, touchmove
and touchend
.
Notes:
Modernizr.touch
will now succeed on page refresh.
Debugging touch events(调试触摸事件)
Multi-touch
Multi-touch events can be simulated if you have a device with touch input, such as a modern Apple MacBook. For further assistance with multi-touch event simulation, see Multi-touch web development.
Back to top
It's often easier to start prototyping on the desktop and then tackle the mobile-specific parts on the devices you intend to support. Device emulation can make this process more straightforward.
(它常常很容易在桌面上启动原型,然后你打算解决支持特定移动部件的设备。设备模拟可以使这个过程更简单)
The DevTools support for device emulation includes native User Agent and dimension overriding. This allows developers to debug mobile browsers on different devices and operating systems via the Overrides menu.
(DevTools设备模拟支持本地用户代理和维度覆盖。这允许开发人员通过覆盖菜单在不同的设备和操作系统调试移动浏览器)
Now you can emulate the exact device metrics of devices like the Galaxy Nexus and the iPhone to test your media query-driven design.
Emulating The User Agent
The result is that first, the User Agent string for the current page changes to Android 2.3. Next, the Device Metrics option has been automatically enabled and theScreen resolution and Font scale factor fields set to those emulating the chosen device.
This allows you to emulate and debug CSS media query breakpoints for devices with ease.
Before:
After:
, the last button under Screen resolution allows us to swap the values of dimensions currently set, should you wish to change the width for the height.
(最后的按钮在是切换你最近一次设置的宽度和高度)
Should you require further customization, Device metrics can be changed at will, with or without the use of a User Agent set.
Additionally, the Fit in window option will rescale the area available to the page to exclude the area occupied by the DevTools.
Notes:
@media only screen and (min-device-width:768px){}
) will also be enabled according to the values defined here. There is presently no other way those can be mimicked.
Back to top
When working with HTML5 geolocation support in an application, it can be useful to debug the output received when using different values for longitude and latitude.
The DevTools support both overriding position values for navigator.geolocation and simulating geolocation not being available via the Overrides menu.
Overriding geolocation positions
Back to top
Many new mobile devices are now shipping with accelerometers, gyroscopes, compasses and other hardware designed to determine capture motion and orientation data.
Web browsers are providing increasingly more access to that new hardware, including such examples as the HTML5 DeviceOrientation events. These events provide developers with information about the orientation, motion and acceleration of the device.
If your application is taking advantage of device orientation events, it can also be useful to override the values received by these events during debugging to avoid the need to test them on a physical mobile device.
Overriding orientation values(重写定位参数)
We have altered the left/right tilt and front/back tilt, in this case resulting in our application being emulated as rotating in a clockwise direction.
Back to top
CSS media types allow us to apply different styles to a page depending on the medium it is being used through (e.g print, screen, tv, braille and so on).
Emulating media types
Before:
After: