Client.url

Baseline Widely available

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

Expérimental: Cette fonction est expérimentale
Puisque cette fonction est toujours en développement dans certains navigateurs, veuillez consulter le tableau de compatibilité pour les préfixes à utiliser selon les navigateurs.
Il convient de noter qu'une fonctionnalité expérimentale peut voir sa syntaxe ou son comportement modifié dans le futur en fonction des évolutions de la spécification.

La propriété url (lecture seule) de l'interface Client retourne l'url du service worker client courant.

Syntaxe

js
var clientUrl = Client.url;

Valeur de retour

Valeur de type USVString.

Exemple

js
self.addEventListener("notificationclick", function (event) {
  console.log("Au click de notification : ", event.notification.tag);
  event.notification.close();

  // Vérification pour savoir si l'évenement est ouvert et
  // se focalise dessus si c'est le cas
  event.waitUntil(
    clients
      .matchAll({
        type: "window",
      })
      .then(function (clientList) {
        for (var i = 0; i < clientList.length; i++) {
          var client = clientList[i];
          if (client.url == "/" && "focus" in client) return client.focus();
        }
        if (clients.openWindow) return clients.openWindow("/");
      }),
  );
});

Spécifications

Specification
Service Workers
# client-url

Compatibilité des navigateurs

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
url

Legend

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

Full support
Full support
No support
No support