API can only be initiated by a user gesture — what does this error mean, and how can you fix it?

When dealing with Web APIs, you come across this error:

API can only be initiated by a user gesture

Image for post

Why does this error happen, and what exactly does it mean?

Why does this happen?

This error means that the API which you are trying to call cannot just be called in your code, it needs to be initiated by a user gesture.

Let’s use the Fullscreen API as an example. This Web API has a method Element.requestFullscreen() which places the target element and the entire browser’s web page into fullscreen mode.

#javascript #programming #web-development #developer

User Gesture Restricted Web APIs
4.20 GEEK