Skip to content

Commit 6f425cb

Browse files
committed
Avoid replacing navigator.serial object
1 parent b4b8ba5 commit 6f425cb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/polyfill.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,8 @@ class Serial extends EventTarget {
290290
}
291291
}
292292

293-
// @ts-ignore
294-
navigator.serial = new Serial()
293+
// copy functions instead of creating a new object,
294+
// so that references to navigator.serial are always valid
295+
const serial = new Serial()
296+
navigator.serial.getPorts = serial.getPorts.bind(serial)
297+
navigator.serial.requestPort = serial.requestPort.bind(serial)

0 commit comments

Comments
 (0)