Skip to content

Commit 0181573

Browse files
committed
fix(Net): check browser support connection
1 parent a65e246 commit 0181573

File tree

1 file changed

+9
-4
lines changed
  • src/BootstrapBlazor/wwwroot/modules

1 file changed

+9
-4
lines changed

src/BootstrapBlazor/wwwroot/modules/net.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ export function init(options) {
99
downlink, networkType: effectiveType, rTT: rtt
1010
});
1111
}
12-
navigator.connection.onchange = e => {
13-
updateState(e.target);
14-
}
1512

1613
const onlineStateChanged = () => {
1714
const indicators = [...document.querySelectorAll('.bb-nt-indicator')];
@@ -31,5 +28,13 @@ export function init(options) {
3128
EventHandler.on(window, 'offline', offlineStateChanged);
3229
});
3330

34-
updateState(navigator.connection);
31+
if (navigator.connection) {
32+
navigator.connection.onchange = e => {
33+
updateState(e.target);
34+
}
35+
updateState(navigator.connection);
36+
}
37+
else {
38+
console.warn('navigator.connection not supported in browser');
39+
}
3540
}

0 commit comments

Comments
 (0)