Use user gesture restricted APIs in the Console
Certain web APIs are user gesture restricted. This means that they can only be called as a result of a user action, such as in a click event handler.
For example, you can't simply put yout website in fullscreen mode by using
However, it can be a pain when you need to test a user gesture restricted API in the Console tool of DevTools.
Thankfully, Chrome, Edge, and Safari let you do it:
- Go to the Console tool.
- Click the Console Settings button in the top-right corner of the tool.
- Clear the Treat code evaluation as user action setting.
- Go the Console tool.
- Check the Emulate User Gesture setting in the toolbar.
And that's it! You can now use and test any APIs in the Console, including those that normally require a user gesture.