navigator.vibrate fix (sometimes missing depending on browser)

This commit is contained in:
Nystik 2026-05-16 00:52:00 +02:00
parent b978b6fa9d
commit c30e105c6e

View file

@ -253,6 +253,22 @@ function installFetchShim() {
};
}
function installVibrateShim() {
if (typeof navigator.vibrate === "function") {
return;
}
// Some Firefox configurations leave navigator.vibrate undefined (gated by dom.vibrator.enabled).
// Obsidian assumes it's always callable, so provide a no-op where it's missing.
try {
Object.defineProperty(navigator, "vibrate", {
configurable: true,
writable: true,
value: () => true,
});
} catch {}
}
function installContextMenuFix() {
// hacky fix to prevent browser from showing context menu while allowing obsidian context menu
window.addEventListener(
@ -271,5 +287,6 @@ export function installGlobals() {
installFetchShim();
installWindowClose();
installWindowOpen();
installVibrateShim();
installContextMenuFix();
}