Cross-platform haptic and audio feedback library for web applications.
⚠️ iOS Safari note: Apple has since disabled programmatic vibration on mobile Safari, so haptic feedback no longer fires there. Audio (WebAudio) feedback still works on iOS, and haptics continue to work on Android Chrome. The library degrades gracefully — calls are safe no-ops where haptics are unavailable.
- 🎵 WebAudio-based click sounds with configurable intensity and gain
- 📳 Haptic feedback for mobile devices (iOS and Android)
- 🔧 Cross-platform compatibility (iOS, Android, web browsers)
- 🎛️ Multiple feedback presets (light, heavy, success, error, etc.)
- 💾 User preference management with pluggable storage
- 🚀 Framework-agnostic (works with React, Vue, vanilla JS)
- 📱 iOS special handling for optimal haptic feedback
bun add @present-day/buzz
# or
npm install @present-day/buzzimport { triggerInteractionFeedback, INTERACTION_FEEDBACK_PRESET } from '@present-day/buzz'
// Trigger light feedback (default)
triggerInteractionFeedback()
// Trigger specific preset
triggerInteractionFeedback({ preset: INTERACTION_FEEDBACK_PRESET.SUCCESS })
// Override individual settings
triggerInteractionFeedback({
hapticEnabled: true,
soundEnabled: false,
preset: INTERACTION_FEEDBACK_PRESET.ERROR
})Triggers haptic and/or audio feedback based on the provided options.
type TriggerInteractionFeedbackOptions = {
preset?: InteractionFeedbackPreset
hapticPreset?: HapticFeedbackPreset
soundPreset?: SoundFeedbackPreset
hapticEnabled?: boolean
soundEnabled?: boolean
storageAdapter?: StorageAdapter
}Cancels any ongoing haptic feedback (if supported by the platform).
Returns whether haptic feedback is available on the current device.
Available presets for both haptic and sound feedback:
LIGHT- Subtle feedbackMEDIUM- Moderate feedbackHEAVY- Strong feedbackSUCCESS- Positive action feedbackERROR- Error/failure feedbackWARNING- Warning/caution feedbackSELECTION- Item selection feedbackBUZZ- Attention-grabbing feedbackNUDGE- Gentle notificationSOFT- Very light feedbackRIGID- Sharp, precise feedback
import {
getHapticFeedbackEnabled,
setHapticFeedbackEnabled,
getSoundFeedbackEnabled,
setSoundFeedbackEnabled
} from '@present-day/buzz'
// Get current preferences
const hapticEnabled = getHapticFeedbackEnabled()
const soundEnabled = getSoundFeedbackEnabled()
// Update preferences
setHapticFeedbackEnabled(false)
setSoundFeedbackEnabled(true)By default, preferences are stored in localStorage. You can provide a custom storage adapter:
import { LocalStorageAdapter, type StorageAdapter } from '@present-day/buzz'
class CustomStorageAdapter implements StorageAdapter {
getItem(key: string): string | null {
// Your custom storage logic
return null
}
setItem(key: string, value: string): void {
// Your custom storage logic
}
}
const customStorage = new CustomStorageAdapter()
// Use with feedback
triggerInteractionFeedback({
storageAdapter: customStorage
})
// Use with preferences
getHapticFeedbackEnabled(true, customStorage)
setHapticFeedbackEnabled(true, customStorage)- iOS Safari: Haptics are no longer available — Apple has disabled programmatic vibration in mobile Safari (audio feedback still works)
- Android Chrome: Uses Vibration API
- Desktop browsers: Audio feedback only (no haptic support)
- WebAudio: Supported in all modern browsers
MIT