Fix JavaScript error in console

This extension causes an annoying log message that tells me about an error that was caught in the extension itself. It could easily be avoided in the first place by adding appropriate checks rather than running into the exception each time and happily telling me about it.

Error message:
Cannot override navigator.credentials:  TypeError: undefined is not a non-null object
in passkeys.js:211:17
    <anonymous> moz-extension://25853ed3-e2b0-47d6-ad17-2b172340068c/content/passkeys.js:204
    <anonymous> moz-extension://25853ed3-e2b0-47d6-ad17-2b172340068c/content/passkeys.js:213
This commit is contained in:
Yves Goergen 2025-10-06 20:42:28 +02:00 committed by GitHub
parent c2dd4cbb98
commit 443b715381
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -201,12 +201,14 @@
// select a software authenticator. This could be removed in the future.
try {
Object.defineProperty(navigator, 'credentials', { value: passkeysCredentials });
Object.defineProperty(window.PublicKeyCredential, 'isConditionalMediationAvailable', {
value: isConditionalMediationAvailable,
});
Object.defineProperty(window.PublicKeyCredential, 'isUserVerifyingPlatformAuthenticatorAvailable', {
value: isUserVerifyingPlatformAuthenticatorAvailable,
});
if (window.PublicKeyCredential) {
Object.defineProperty(window.PublicKeyCredential, 'isConditionalMediationAvailable', {
value: isConditionalMediationAvailable,
});
Object.defineProperty(window.PublicKeyCredential, 'isUserVerifyingPlatformAuthenticatorAvailable', {
value: isUserVerifyingPlatformAuthenticatorAvailable,
});
}
} catch (err) {
console.log('Cannot override navigator.credentials: ', err);
}