Skip to content

Commit bc23f2d

Browse files
committed
Merge pull request #453 from tehhi/request_get
Credential Manager API. Use get instead of request.
2 parents e9c714e + 0e278b2 commit bc23f2d

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

demos/credential-management-api-test/credential.html

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,32 @@ <h1>AN AMAZING DEMO OF THE ASTOUNDING CREDENTIAL MANAGER API!</h1>
8686
document.querySelector('button').addEventListener('click', function (e) {
8787
e.preventDefault();
8888
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+
}
99102
}
100103
});
101104

102105
/*********************************************************************************
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 *
104107
*********************************************************************************/
108+
function processCredentialsRequest(credentials) {
109+
if (!c) {
110+
addIssue("No <code>Credential</code> retrieved.");
111+
return;
112+
}
113+
addNote("Retrieved: " + credentialToString(c));
114+
}
105115

106116
function createCredentialFromForm(form) {
107117
try {

0 commit comments

Comments
 (0)