Chrome Passkey "Page Does Not Have Focus" Error After Bitwarden Fallback
Fix WebAuthn NotAllowedError "page does not have focus" when a password manager hands a passkey request back to Chrome, by retrying with the native API.
Adding or using a passkey fails in Chrome when a password manager extension (such as Bitwarden) shows its passkey popup first and the user picks the option to use their device instead.
NotAllowedError: The operation is not allowed at this time because the page does not have focus.
Cause
Password manager extensions replace navigator.credentials.create and navigator.credentials.get in the page so they can offer their own passkeys. When the user chooses âUse your device or hardware keyâ (Bitwarden), the extension calls the browserâs original function again as soon as the page reports document.hasFocus().
Chromeâs WebAuthn âfocusâ check is really a visibility check: the request is refused unless the tabâs contents are VISIBLE. Straight after the extensionâs popup window closes, Chrome can still treat the tab as covered, so the handed-back request fails with the focus error. Whether it happens depends on timing, so one site can hit it while another with similar code does not.
Fix
Catch the focus error in the pageâs own passkey code, wait until the tab is visible and focused, then retry. Retry with the browserâs native function rather than navigator.credentials.create, because the extension only overrides the methods on the navigator.credentials object: the originals are still on CredentialsContainer.prototype. The retry therefore goes straight to the browserâs prompt (which the user already chose) instead of reopening the extensionâs popup.
Add a helper that detects the error and waits for the page:
function isFocusError(error: unknown): boolean {
return error instanceof Error && error.name === "NotAllowedError" && /focus/i.test(error.message);
}
function pageReady(limitMs = 10_000): Promise<void> {
return new Promise((resolve) => {
const started = Date.now();
const check = () => {
if ((document.visibilityState === "visible" && document.hasFocus()) || Date.now() - started > limitMs) {
setTimeout(resolve, 300); // a moment more for the browser to see the window uncovered
return;
}
setTimeout(check, 100);
};
check();
});
}
const nativeCredentials = {
create: (options: CredentialCreationOptions) =>
CredentialsContainer.prototype.create.call(navigator.credentials, options),
get: (options: CredentialRequestOptions) =>
CredentialsContainer.prototype.get.call(navigator.credentials, options),
};
Then wrap the call: the first attempt goes through navigator.credentials (so the password manager can still offer its own passkeys), and retries use the native functions:
async function createPasskey(publicKey: PublicKeyCredentialCreationOptions): Promise<Credential | null> {
const controller = new AbortController();
for (let attempt = 0; ; attempt += 1) {
const request = { publicKey, signal: controller.signal };
try {
return attempt === 0
? await navigator.credentials.create(request)
: await nativeCredentials.create(request);
} catch (error) {
if (!isFocusError(error) || attempt >= 3) {
throw error;
}
await pageReady();
}
}
}
Do the same for navigator.credentials.get when signing in with a passkey.
If a library such as @simplewebauthn/browser makes the browser call for you, call navigator.credentials directly for this step instead (encoding the response to the JSON the server library expects), so the retry can be added.
Verify
Click the button that adds a passkey, and choose the âuse your deviceâ option in the password managerâs popup. The browserâs own passkey prompt (for example iCloud Keychain on macOS) should now appear. Logging inside the retry branch confirms it was needed:
The page wasn't focused yet; retrying with the browser's own prompt.
Notes
- Nothing a site sends (such as WebAuthn
hintsorauthenticatorAttachment) stops an extension intercepting the request. The only global way to get the browserâs prompt first is to turn off the extensionâs passkey feature, e.g. Bitwarden â Settings â Notifications â âAsk to save and use passkeysâ, or to add the site to its excluded domains. - In Bitwarden, the Close button inside the popup cancels the request (plain
NotAllowedError, no fallback). Only âUse your device or hardware keyâ or closing the popup window hands it back to the browser. - Tested with Chrome on macOS and the Bitwarden browser extension.
- This is not specific to Bitwarden. Any password manager extension that shows its passkey prompt in its own window and then hands the request back to the browser can trigger the same error, because the browser may still see the tab as covered when the request arrives. The retry above works the same way for them.