File tree Expand file tree Collapse file tree 1 file changed +21
-11
lines changed
demos/credential-management-api-test Expand file tree Collapse file tree 1 file changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -86,22 +86,32 @@ <h1>AN AMAZING DEMO OF THE ASTOUNDING CREDENTIAL MANAGER API!</h1>
86
86
document . querySelector ( 'button' ) . addEventListener ( 'click' , function ( e ) {
87
87
e . preventDefault ( ) ;
88
88
if ( navigator . credentials ) {
89
- navigator . credentials . request ( ) . then ( function ( c ) {
90
- if ( ! c ) {
91
- addIssue ( "No <code>Credential</code> retrieved." ) ;
92
- return ;
93
- }
94
-
95
- addNote ( "Retrieved: " + credentialToString ( c ) ) ;
96
- } , function ( e ) {
97
- addIssue ( "Error: <code>" + e . message + "</code>" ) ;
98
- } ) ;
89
+ try {
90
+ navigator . credentials . request ( ) . then (
91
+ processCredentialsRequest ( c ) , function ( e ) {
92
+ addIssue ( "Error: <code>" + e . message + "</code>" ) ;
93
+ } ) ;
94
+ } catch ( e ) {
95
+ if ( ! ( e instanceof TypeError ) )
96
+ throw e ;
97
+ navigator . credentials . get ( ) . then (
98
+ processCredentialsRequest ( c ) , function ( e ) {
99
+ addIssue ( "Error: <code>" + e . message + "</code>" ) ;
100
+ } ) ;
101
+ }
99
102
}
100
103
} ) ;
101
104
102
105
/*********************************************************************************
103
- * HELPER FUNCTIONS THAT HAVE NOTHING TO DO WITH CREDENTIAL MANAGEMENT IN ITSELF *
106
+ * HELPER FUNCTIONS THAT HAVE NOTHING TO DO WITH CREDENTIAL MANAGEMENT IN ITSELF *
104
107
*********************************************************************************/
108
+ function processCredentialsRequest ( credentials ) {
109
+ if ( ! c ) {
110
+ addIssue ( "No <code>Credential</code> retrieved." ) ;
111
+ return ;
112
+ }
113
+ addNote ( "Retrieved: " + credentialToString ( c ) ) ;
114
+ }
105
115
106
116
function createCredentialFromForm ( form ) {
107
117
try {
You can’t perform that action at this time.
0 commit comments