Skip to content

Commit 7a8fb24

Browse files
committed
fix worker dead: no ResizeObserver
1 parent 43692d3 commit 7a8fb24

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

page/focus.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ export function redrawCaretAndPreeditUnderline() {
3838
}
3939
}
4040

41-
const resizeObserver = new ResizeObserver(redrawCaretAndPreeditUnderline)
41+
const resizeObserver = (() => {
42+
if (globalThis.ResizeObserver) {
43+
return new ResizeObserver(redrawCaretAndPreeditUnderline)
44+
}
45+
return null // webworker
46+
})()
4247

4348
export function focus() {
4449
if (!isInputElement(document.activeElement)) {
@@ -62,7 +67,7 @@ export function focus() {
6267
showKeyboard()
6368
resetStacks(input.value)
6469
}
65-
resizeObserver.observe(input)
70+
resizeObserver?.observe(input)
6671
input.addEventListener('mousedown', resetInput)
6772
originalSpellCheck = input.spellcheck
6873
const isPassword = input.tagName === 'INPUT' && input.type === 'password'
@@ -89,7 +94,7 @@ export function blur() {
8994
hideKeyboard()
9095
removeCaret()
9196
}
92-
resizeObserver.unobserve(input)
97+
resizeObserver?.unobserve(input)
9398
input.spellcheck = originalSpellCheck
9499
input = null
95100
Module.ccall('focus_out', 'void', [], [])

0 commit comments

Comments
 (0)