CredentialsContainer: store() Methode

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Sicherer Kontext: Diese Funktion ist nur in sicheren Kontexten (HTTPS) in einigen oder allen unterstützenden Browsern verfügbar.

Die store()-Methode des CredentialsContainer speichert ein Set von Anmeldeinformationen für den Benutzer in einer Credential-Instanz und gibt diese in einem Promise zurück.

Hinweis: Diese Methode ist auf oberste Kontexte beschränkt. Aufrufe innerhalb eines <iframe>-Elements werden ohne Wirkung aufgelöst.

Syntax

js
store(credentials)

Parameter

credentials

Eine gültige Credential-Instanz.

Rückgabewert

Ein Promise, das auf undefined aufgelöst wird.

Ausnahmen

NotAllowedError DOMException

Wird ausgelöst, wenn es bereits eine Anmeldeinformation des gleichen Typs wie die aktuelle gibt, die in Bearbeitung ist.

Beispiele

Speichern einer Passwort-Anmeldeinformation bei erfolgreicher Authentifizierung

Dieses Codebeispiel wird ausgeführt, nachdem sich ein Benutzer angemeldet oder registriert hat und der Server die Anmeldeinformation als korrekt bestätigt hat.

js
// Check if the browser supports password credentials (and the Credential Management API)
if ("PasswordCredential" in window) {
  let credential = new PasswordCredential({
    id: "example-username",
    name: "Carina Anand", // In case of a login, the name comes from the server.
    password: "correct horse battery staple",
  });

  navigator.credentials.store(credential).then(
    () => {
      console.info("Credential stored in the user agent's credential manager.");
    },
    (err) => {
      console.error("Error while storing the credential: ", err);
    },
  );
}

Spezifikationen

Specification
Credential Management Level 1
# dom-credentialscontainer-store

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
store

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support