@@ -115,9 +115,18 @@ export default function WebRTCVideo() {
115115 const isFullscreenEnabled = document . fullscreenEnabled ;
116116
117117 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
121130 } , [ ] ) ;
122131
123132 const requestPointerLock = useCallback ( async ( ) => {
@@ -128,18 +137,25 @@ export default function WebRTCVideo() {
128137 const isPointerLockGranted = await checkNavigatorPermissions ( "pointer-lock" ) ;
129138
130139 if ( isPointerLockGranted && settings . mouseMode === "relative" ) {
131- await videoElm . current . requestPointerLock ( ) ;
140+ try {
141+ await videoElm . current . requestPointerLock ( ) ;
142+ } catch {
143+ // ignore errors
144+ }
132145 }
133146 } , [ checkNavigatorPermissions , isPointerLockPossible , settings . mouseMode ] ) ;
134147
135148 const requestKeyboardLock = useCallback ( async ( ) => {
136149 if ( videoElm . current === null ) return ;
137150
138151 const isKeyboardLockGranted = await checkNavigatorPermissions ( "keyboard-lock" ) ;
139- if ( isKeyboardLockGranted ) {
140- if ( "keyboard" in navigator ) {
152+
153+ if ( isKeyboardLockGranted && "keyboard" in navigator ) {
154+ try {
141155 // @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
143159 }
144160 }
145161 } , [ checkNavigatorPermissions ] ) ;
@@ -148,8 +164,12 @@ export default function WebRTCVideo() {
148164 if ( videoElm . current === null || document . fullscreenElement !== videoElm . current ) return ;
149165
150166 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+ }
153173 }
154174 } , [ ] ) ;
155175
0 commit comments