From 2c399acefd8de2e02df30b379015ac354be2b16e Mon Sep 17 00:00:00 2001 From: Derek Scruggs Date: Fri, 12 Jun 2026 10:10:12 -0500 Subject: [PATCH 1/2] Do not throw when navigator.credentials cannot be redefined. On WebKit (all iOS browsers), `navigator.credentials` is a non-configurable property, so the `Object.defineProperty()` call used since 3.2.1 to install the anti-clobber proxy throws a TypeError, causing `load()`/`loadOnce()` to reject and CHAPI to never initialize. Wrap the call in a try/catch and fall back to plain assignment; if that also fails, continue without the proxy, since `get` and `store` have already been replaced on the existing `navigator.credentials` object and only protection against later overwrites of the property itself is lost. Addresses #51. Co-Authored-By: Claude Fable 5 --- CHANGELOG.md | 8 ++++++++ lib/index.js | 22 +++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) 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..bd99b8f 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. All rights reserved. */ /* 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; From 4d050da4e8ffd48e622bec85867d58e09c4b5513 Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Fri, 12 Jun 2026 11:24:45 -0400 Subject: [PATCH 2/2] Fix file header. --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index bd99b8f..62be7eb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,5 @@ /*! - * Copyright (c) 2017-2026 Digital Bazaar, Inc. All rights reserved. + * Copyright (c) 2017-2026 Digital Bazaar, Inc. */ /* global navigator, window */ import {WebAppContext} from 'web-request-rpc';