Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

ServiceWorkerContainer.register()

Diese Übersetzung ist unvollständig. Bitte helfen Sie, diesen Artikel aus dem Englischen zu übersetzen.

Dies ist eine experimentelle Technologie
Da diese Technologie noch nicht definitiv implementiert wurde, sollte die Browser Kompatibilität beachtet werden. Es ist auch möglich, dass der Syntax in einer späteren Spezifikation noch geändert wird.

Die register() Methode von dem ServiceWorkerContainer Schnittstelle erstellt oder aktualisiert eine ServiceWorkerRegistration für die gegebene scriptURL.

If successful, a service worker registration ties the provided script URL to a scope, which is subsequently used for navigation matching. If the method can't return a ServiceWorkerRegistration, it returns a Promise. You can call this method unconditionally from the controlled page, i.e., you don't need to first check whether there's an active registration.

Syntax

ServiceWorkerContainer.register(scriptURL, options).then(function(ServiceWorkerRegistration) {
  // Do something with ServiceWorkerRegistration.
});

Parameters

scriptURL
The URL of the service worker script.
options Optional
An options object to provide options upon registration. Currently available options are:
  • scope: A USVString representing a URL that defines a service worker's registration scope; what range of URLs a service worker can control. This is usually a relative URL. The default value is the URL you'd get if you resolved './' using the service worker script's location as the base.

Returns

A Promise that resolves to a ServiceWorkerRegistration object.

Example

if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('service-worker.js', {scope: './'}).then(function(registration) {
    document.querySelector('#status').textContent = 'succeeded';
  }).catch(function(error) {
    document.querySelector('#status').textContent = error;
  });
} else {
  // The current browser doesn't support service workers.
  var aElement = document.createElement('a');
  aElement.href = 'https://www.chromium.org/blink/serviceworker/service-worker-faq';
  aElement.textContent = 'unavailable';
  document.querySelector('#status').appendChild(aElement);
}

Specifications

Specification Status Comment
Service Workers
Die Definition von 'ServiceWorkerContainer' in dieser Spezifikation.
Arbeitsentwurf Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 40.0 44.0 (44.0) Nicht unterstützt 24 Nicht unterstützt
Feature Android Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support ? 44.0 (44.0) (Ja) Nicht unterstützt ? Nicht unterstützt 40.0

Schlagwörter des Dokuments und Mitwirkende

 Mitwirkende an dieser Seite: heniz
 Zuletzt aktualisiert von: heniz,