user-gesture
v1.0.1
Published
Reserve calling function that is needed user gesture(or user activation)
Maintainers
Readme
user-gesture
Reserve function calls that must be executed during a user gesture (user activation).
Some Web APIs (such as clipboard, audio playback, fullscreen, etc.) require execution inside a user gesture event handler. This library lets you queue functions and execute them when a supported user event occurs.
Installation
bash
npm install user-gesture
Usage
`js import { post } from "user-gesture";
post(({ postedAt, event }) => { console.log("Executed during user gesture", postedAt, event); // Call APIs that require user activation here }); `
The queued functions will run on the next supported user event such as:
- click
- dblclick
- contextmenu
- mouseup
- pointerup
- touchend
- change
- reset
- submit
API
setHandler(element: EventTarget)
Attach user gesture listeners to the specified element. By default, setHandler(document.body) is automatically called.
post(func: (context) => void)
Queue a function to be executed on the next user gesture.
run(event?)
Manually trigger execution of queued functions.
Build
bash
npm run build
License
MIT
