{"record":{"id":"3fce0758a68a7221","repo":"unoplatform/uno","slug":"keyboard-lock-is-not-supported-by-this-browser","errorCode":null,"errorMessage":"Keyboard lock is not supported by this browser.","messagePattern":"Keyboard lock is not supported by this browser\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/Uno.UI.Runtime.Skia.WebAssembly.Browser/ts/Runtime/BrowserInputHelper.ts","lineNumber":12,"sourceCode":"namespace Uno.UI.Runtime.Skia {\n\texport class BrowserInputHelper {\n\t\t// Read by BrowserPointerInputSource.onPointerEventReceived\n\t\tpublic static isBrowserZoomEnabled: boolean = true;\n\n\t\tpublic static setBrowserZoomEnabled(enabled: boolean): void {\n\t\t\tBrowserInputHelper.isBrowserZoomEnabled = enabled;\n\t\t}\n\n\t\tpublic static async lockKeys(keyCodes: string[]): Promise<void> {\n\t\t\tif (!BrowserInputHelper.isKeyboardLockSupported()) {\n\t\t\t\tthrow new Error(\"Keyboard lock is not supported by this browser.\");\n\t\t\t}\n\n\t\t\tconst kb = (navigator as any).keyboard;\n\t\t\tawait kb.lock(\n\t\t\t\tkeyCodes.length > 0 ? keyCodes : undefined\n\t\t\t);\n\t\t}\n\n\t\tpublic static isKeyboardLockSupported(): boolean {\n\t\t\tconst kb = (navigator as any).keyboard;\n\t\t\treturn !!kb && typeof kb.lock === \"function\" && typeof kb.unlock === \"function\";\n\t\t}\n\n\t\tpublic static unlockKeys(): void {\n\t\t\t(navigator as any).keyboard?.unlock();\n\t\t}\n\t}\n}","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/Uno.UI.Runtime.Skia.WebAssembly.Browser/ts/Runtime/BrowserInputHelper.ts#L1-L30","documentation":"Thrown by BrowserInputHelper.lockKeys when the browser does not support the Keyboard Lock API (navigator.keyboard.lock). The isKeyboardLockSupported() guard checks for the presence of navigator.keyboard with both lock and unlock methods. Firefox and Safari do not implement this API; only Chromium-based browsers (Chrome, Edge, Opera) do.","triggerScenarios":"C# calls the keyboard-lock interop which calls BrowserInputHelper.lockKeys on a non-Chromium browser, or on a Chromium browser where the feature flag is disabled. Also fails if the document is not served in a secure context (Keyboard Lock requires HTTPS or localhost).","commonSituations":"Running the WASM app in Firefox or Safari, running over plain HTTP (not localhost), or on an older Chromium version predating Keyboard Lock support.","solutions":["Check BrowserInputHelper.isKeyboardLockSupported() (or navigator.keyboard availability) before calling lockKeys and fall back gracefully.","Ensure the app is served over HTTPS or localhost — Keyboard Lock is a secure-context-only API.","Inform the user that keyboard lock is Chromium-only and provide a non-locking alternative."],"exampleFix":"// before\nawait BrowserInputHelper.lockKeys(keyCodes);\n\n// after\nif (BrowserInputHelper.isKeyboardLockSupported()) {\n    await BrowserInputHelper.lockKeys(keyCodes);\n} else {\n    console.warn('Keyboard lock not available in this browser.');\n}","handlingStrategy":"validation","validationCode":"if (!BrowserInputHelper.isKeyboardLockSupported()) {\n    // Skip keyboard lock — browser does not support it\n    return;\n}\nawait BrowserInputHelper.lockKeys(keyCodes);","typeGuard":"// Feature-detect the Keyboard Lock API\nfunction supportsKeyboardLock(): boolean {\n    const kb = (navigator as any).keyboard;\n    return !!kb && typeof kb.lock === 'function' && typeof kb.unlock === 'function';\n}","tryCatchPattern":"try {\n    await BrowserInputHelper.lockKeys(keyCodes);\n} catch (e) {\n    if (e.message === 'Keyboard lock is not supported by this browser.') {\n        // Graceful degradation — proceed without key lock\n    } else { throw e; }\n}","preventionTips":["Always call isKeyboardLockSupported() before lockKeys.","Serve the WASM app over HTTPS or localhost (secure context required).","Document that keyboard lock is Chromium-only in your app's requirements."],"tags":["wasm","browser","keyboard","feature-detection","typescript"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}