From 87516cc22823931d680644bcbb24c4dde181a273 Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Fri, 12 Jul 2024 07:47:16 +0200 Subject: [PATCH] fix: add additional check for navigator.keyboard --- src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 99e3a6a..33f138c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -547,7 +547,7 @@ function windowBlur() { } async function getKeyboardLayoutMap() { - if ('keyboard' in navigator && typeof navigator.keyboard.getLayoutMap === 'function') { + if ('keyboard' in navigator && navigator.keyboard && typeof navigator.keyboard.getLayoutMap === 'function') { try { keyboardLayoutMap = await navigator.keyboard.getLayoutMap() dispatchEvent('layoutchange') @@ -658,7 +658,7 @@ async function init(options?: { chordTimeout?: number }) { window.addEventListener('blur', windowBlur) window.addEventListener('pagehide', windowBlur) - if ('keyboard' in navigator && typeof navigator.keyboard.addEventListener === 'function') { + if ('keyboard' in navigator && navigator.keyboard && typeof navigator.keyboard.addEventListener === 'function') { navigator.keyboard.addEventListener('layoutchange', getKeyboardLayoutMap) } await getKeyboardLayoutMap() @@ -685,7 +685,7 @@ async function destroy() { window.removeEventListener('blur', windowBlur) window.removeEventListener('pagehide', windowBlur) - if ('keyboard' in navigator && typeof navigator.keyboard.removeEventListener === 'function') { + if ('keyboard' in navigator && navigator.keyboard && typeof navigator.keyboard.removeEventListener === 'function') { navigator.keyboard.removeEventListener('layoutchange', getKeyboardLayoutMap) }