Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add additional check for navigator.keyboard #9

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand All @@ -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)
}

Expand Down