diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ff4704..071a99d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # credential-handler-polyfill ChangeLog +## 4.0.2 - 2026-06-dd + +### Fixed +- Do not throw during `load()` on browsers (e.g., WebKit/iOS) where + `navigator.credentials` cannot be redefined via `Object.defineProperty`; + fall back to plain assignment or, failing that, skip installing the + proxy that protects against subsequent overwrites. + ## 4.0.1 - 2025-12-16 ### Fixed diff --git a/lib/index.js b/lib/index.js index 9d15cd0..62be7eb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,5 @@ /*! - * Copyright (c) 2017-2024 Digital Bazaar, Inc. All rights reserved. + * Copyright (c) 2017-2026 Digital Bazaar, Inc. */ /* global navigator, window */ import {WebAppContext} from 'web-request-rpc'; @@ -104,10 +104,22 @@ export async function load(options = { } }); - Object.defineProperty(navigator, 'credentials', { - value: navCredentialsProxy, - writable: true - }); + try { + Object.defineProperty(navigator, 'credentials', { + value: navCredentialsProxy, + writable: true + }); + } catch(e) { + // on WebKit, `navigator.credentials` is a non-configurable property + // that cannot be redefined as a data property; fall back to plain + // assignment and, if that also fails, continue without the proxy -- + // `get` and `store` have already been replaced on the existing + // `navigator.credentials` above, so only the protection against + // subsequent overwrites of `navigator.credentials` itself is lost + try { + navigator.credentials = navCredentialsProxy; + } catch(e2) {} + } window.CredentialManager = CredentialManager; window.WebCredential = WebCredential;