Do not throw when navigator.credentials cannot be redefined#52
Merged
Conversation
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 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #51.
On WebKit (all iOS browsers, desktop Safari),
navigator.credentialsis a non-configurable property, so theObject.defineProperty()call used since 3.2.1 to install the anti-clobber proxy throws aTypeError, causingload()/loadOnce()to reject and CHAPI to never initialize.Changes
defineProperty()call in a try/catch.getandstorehave already been replaced directly on the existingnavigator.credentialsobject earlier inload()— only the protection against subsequent overwrites of the property itself is lost, matching the pre-3.2.1 behavior that works on iOS.Testing
npm run lintpasses; webpack build compiles.loadOnce()rejects withTypeError: Attempting to change writable attribute of unconfigurable property; with the fix,loadOnce()resolves,window.WebCredentialis defined, andnavigator.credentials.get/storeare patched.🤖 Generated with Claude Code