@@ -115,9 +115,18 @@ export default function WebRTCVideo() {
115
115
const isFullscreenEnabled = document . fullscreenEnabled ;
116
116
117
117
const checkNavigatorPermissions = useCallback ( async ( permissionName : string ) => {
118
- const name = permissionName as PermissionName ;
119
- const { state } = await navigator . permissions . query ( { name } ) ;
120
- return state === "granted" ;
118
+ if ( ! navigator . permissions || ! navigator . permissions . query ) {
119
+ return false ; // if can't query permissions, assume NOT granted
120
+ }
121
+
122
+ try {
123
+ const name = permissionName as PermissionName ;
124
+ const { state } = await navigator . permissions . query ( { name } ) ;
125
+ return state === "granted" ;
126
+ } catch {
127
+ // ignore errors
128
+ }
129
+ return false ; // if query fails, assume NOT granted
121
130
} , [ ] ) ;
122
131
123
132
const requestPointerLock = useCallback ( async ( ) => {
@@ -128,18 +137,25 @@ export default function WebRTCVideo() {
128
137
const isPointerLockGranted = await checkNavigatorPermissions ( "pointer-lock" ) ;
129
138
130
139
if ( isPointerLockGranted && settings . mouseMode === "relative" ) {
131
- await videoElm . current . requestPointerLock ( ) ;
140
+ try {
141
+ await videoElm . current . requestPointerLock ( ) ;
142
+ } catch {
143
+ // ignore errors
144
+ }
132
145
}
133
146
} , [ checkNavigatorPermissions , isPointerLockPossible , settings . mouseMode ] ) ;
134
147
135
148
const requestKeyboardLock = useCallback ( async ( ) => {
136
149
if ( videoElm . current === null ) return ;
137
150
138
151
const isKeyboardLockGranted = await checkNavigatorPermissions ( "keyboard-lock" ) ;
139
- if ( isKeyboardLockGranted ) {
140
- if ( "keyboard" in navigator ) {
152
+
153
+ if ( isKeyboardLockGranted && "keyboard" in navigator ) {
154
+ try {
141
155
// @ts -expect-error - keyboard lock is not supported in all browsers
142
- await navigator . keyboard . lock ( ) ;
156
+ await navigator . keyboard . lock ( ) ;
157
+ } catch {
158
+ // ignore errors
143
159
}
144
160
}
145
161
} , [ checkNavigatorPermissions ] ) ;
@@ -148,8 +164,12 @@ export default function WebRTCVideo() {
148
164
if ( videoElm . current === null || document . fullscreenElement !== videoElm . current ) return ;
149
165
150
166
if ( "keyboard" in navigator ) {
151
- // @ts -expect-error - keyboard unlock is not supported in all browsers
152
- await navigator . keyboard . unlock ( ) ;
167
+ try {
168
+ // @ts -expect-error - keyboard unlock is not supported in all browsers
169
+ await navigator . keyboard . unlock ( ) ;
170
+ } catch {
171
+ // ignore errors
172
+ }
153
173
}
154
174
} , [ ] ) ;
155
175
0 commit comments