diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
| commit | 074785cea106179cb3305637055ab0a009ca74f2 (patch) | |
| tree | e6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/ru/web/api/serviceworkerregistration | |
| parent | da78a9e329e272dedb2400b79a3bdeebff387d47 (diff) | |
| download | translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2 translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip | |
initial commit
Diffstat (limited to 'files/ru/web/api/serviceworkerregistration')
4 files changed, 563 insertions, 0 deletions
diff --git a/files/ru/web/api/serviceworkerregistration/index.html b/files/ru/web/api/serviceworkerregistration/index.html new file mode 100644 index 0000000000..8daa8d7b98 --- /dev/null +++ b/files/ru/web/api/serviceworkerregistration/index.html @@ -0,0 +1,145 @@ +--- +title: ServiceWorkerRegistration +slug: Web/API/ServiceWorkerRegistration +tags: + - API + - Interface + - NeedsTranslation + - Offline + - Reference + - Service Workers + - Service worker API + - ServiceWorkerRegistration + - TopicStub + - Workers +translation_of: Web/API/ServiceWorkerRegistration +--- +<div> +<div>{{SeeCompatTable}}{{APIRef("Service Workers API")}}</div> +</div> + +<p><span class="seoSummary">Интерфейс <code>ServiceWorkerRegistration</code> ссылается на регистрацию Service Worker. Вы можете зарегистрировать Service Worker, чтобы контролировать одну или несколько страниц на одном домене.</span></p> + +<p>The lifetime of a service worker registration is beyond that of the <code>ServiceWorkerRegistration</code> objects that represent them within the lifetime of their corresponding service worker clients. The browser maintains a persistent list of active <code>ServiceWorkerRegistration</code> objects.</p> + +<div class="note"> +<p><strong>Эта функция доступна в</strong> <a href="/en-US/docs/Web/API/Web_Workers_API">Web Workers</a>.</p> +</div> + +<h2 id="Свойства">Свойства</h2> + +<p><em>Also implements properties from its parent interface, </em>{{domxref("EventTarget")}}.</p> + +<dl> + <dt>{{domxref("ServiceWorkerRegistration.scope")}} {{readonlyinline}}</dt> + <dd>Returns a unique identifier for a service worker registration. This must be on the same origin as the document that registers the {{domxref("ServiceWorker")}}.</dd> + <dt>{{domxref("ServiceWorkerRegistration.installing")}} <strong style="font-weight: bold;">{{readonlyinline}}</strong></dt> + <dd>Returns a service worker whose state is <code>installing</code>. This is initially set to <code>null</code>.</dd> + <dt>{{domxref("ServiceWorkerRegistration.waiting")}} <strong style="font-weight: bold;">{{readonlyinline}}</strong></dt> + <dd>Returns a service worker whose state is <code>waiting</code>. This is initially set to <code>null</code>.</dd> + <dt>{{domxref("ServiceWorkerRegistration.active")}} <strong style="font-weight: bold;">{{readonlyinline}}</strong></dt> + <dd>Returns a service worker whose state is either <code>activating</code> or <code>activated</code>. This is initially set to <code>null</code>. An active worker will control a {{domxref("ServiceWorkerClient")}} if the client's URL falls within the scope of the registration (the <code>scope</code> option set when {{domxref("ServiceWorkerContainer.register")}} is first called.)</dd> + <dt>{{domxref("ServiceWorkerRegistration.navigationPreload")}} {{readonlyinline}}</dt> + <dd>Returns the instance of {{domxref("NavigationPreloadManager")}} associated with the current service worker registration.</dd> + <dt>{{domxref("serviceWorkerRegistration.periodicSync")}} {{non-standard_inline}} {{readonlyinline}}</dt> + <dd>Returns a reference to the {{domxref("PeriodicSyncManager")}} interface, which manages periodic background synchronization processes.</dd> + <dt>{{domxref("ServiceWorkerRegistration.pushManager")}} {{readonlyinline}}</dt> + <dd>Returns a reference to the {{domxref("PushManager")}} interface for managing push subscriptions including subscribing, getting an active subscription, and accessing push permission status.</dd> + <dt>{{domxref("ServiceWorkerRegistration.sync")}} <strong style="font-weight: bold; line-height: 19.0909080505371px;">{{non-standard_inline}} </strong>{{readonlyinline}} </dt> + <dd>Returns a reference to the {{domxref("SyncManager")}} interface, which manages background synchronization processes.</dd> +</dl> + +<h3 id="Event_handlers">Event handlers</h3> + +<dl> + <dt>{{domxref("ServiceWorkerRegistration.onupdatefound")}} {{readonlyinline}}</dt> + <dd>An <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventListener" title="This method is called whenever an event occurs of the type for which the EventListener interface was registered."><code>EventListener</code></a> property called whenever an event of type <code>updatefound</code> is fired; it is fired any time the {{domxref("ServiceWorkerRegistration.installing")}} property acquires a new service worker.</dd> +</dl> + +<h2 id="Методы">Методы</h2> + +<p><em>Also implements methods from its parent interface, </em>{{domxref("EventTarget")}}.</p> + +<dl> + <dt>{{domxref("ServiceWorkerRegistration.getNotifications()")}}</dt> + <dd>Returns a {{jsxref("Promise")}} that resolves to an array of {{domxref("Notification")}} objects.</dd> + <dt>{{domxref("ServiceWorkerRegistration.showNotification()")}}</dt> + <dd>Displays the notification with the requested title.</dd> + <dt>{{domxref("ServiceWorkerRegistration.update()")}}</dt> + <dd>Checks the server for an updated version of the service worker without consulting caches.</dd> + <dt>{{domxref("ServiceWorkerRegistration.unregister()")}}</dt> + <dd>Unregisters the service worker registration and returns a {{jsxref("Promise")}}. The service worker will finish any ongoing operations before it is unregistered.</dd> +</dl> + +<h2 id="Примеры">Примеры</h2> + +<p>In this example, the code first checks whether the browser supports service workers and if so registers one. Next, it adds and <code>updatefound</code> event in which it uses the service worker registration to listen for further changes to the service worker's state. If the service worker hasn't changed since the last time it was registered, than the <code>updatefound</code> event will not be fired.</p> + +<pre class="brush: js">if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/sw.js') + .then(function(registration) { + registration.addEventListener('updatefound', function() { + // If updatefound is fired, it means that there's + // a new service worker being installed. + var installingWorker = registration.installing; + console.log('A new service worker is being installed:', + installingWorker); + + // You can listen for changes to the installing service worker's + // state via installingWorker.onstatechange + }); + }) + .catch(function(error) { + console.log('Service worker registration failed:', error); + }); +} else { + console.log('Service workers are not supported.'); +}</pre> + +<h2 id="Спецификации">Спецификации</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Спецификация</th> + <th scope="col">Статус</th> + <th scope="col">Комментарии</th> + </tr> + <tr> + <td>{{SpecName('Service Workers', '#service-worker-registration-obj', 'ServiceWorkerRegistration')}}</td> + <td>{{Spec2('Service Workers')}}</td> + <td>Изначальное определение.</td> + </tr> + <tr> + <td>{{SpecName('Push API', '#widl-ServiceWorkerRegistration-pushManager', 'PushManager')}}</td> + <td>{{Spec2('Push API')}}</td> + <td>Добавлено свойство {{domxref("PushManager","pushManager")}}.</td> + </tr> + <tr> + <td>{{SpecName('Web Notifications')}}</td> + <td>{{Spec2('Web Notifications')}}</td> + <td>Добавлены методы {{domxref("ServiceWorkerRegistration.showNotification()","showNotification()")}} и {{domxref("ServiceWorkerRegistration.getNotifications()","getNotifications()")}}.</td> + </tr> + <tr> + <td>{{SpecName('Background Sync')}}</td> + <td>{{Spec2('Background Sync')}}</td> + <td>Добавлено свойство {{domxref("ServiceWorkerRegistration.sync","sync")}}.</td> + </tr> + </tbody> +</table> + +<h2 id="Совместимость">Совместимость</h2> + + + +<p>{{Compat("api.ServiceWorkerRegistration")}}</p> + +<h2 id="Смотрите_также">Смотрите также</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/ServiceWorker_API/Using_Service_Workers">Использование Service Workers</a></li> + <li><a href="https://github.com/mdn/sw-test">Service workers basic code example</a></li> + <li><a href="https://jakearchibald.github.io/isserviceworkerready/">Is ServiceWorker ready?</a></li> + <li>{{jsxref("Promise")}}</li> + <li><a href="/en-US/docs/Web/Guide/Performance/Using_web_workers">Using web workers</a></li> +</ul> diff --git a/files/ru/web/api/serviceworkerregistration/pushmanager/index.html b/files/ru/web/api/serviceworkerregistration/pushmanager/index.html new file mode 100644 index 0000000000..ceaa0bc41e --- /dev/null +++ b/files/ru/web/api/serviceworkerregistration/pushmanager/index.html @@ -0,0 +1,72 @@ +--- +title: ServiceWorkerRegistration.pushManager +slug: Web/API/ServiceWorkerRegistration/pushManager +translation_of: Web/API/ServiceWorkerRegistration/pushManager +--- +<div>{{SeeCompatTable}}{{APIRef("Service Workers API")}}</div> + +<p>Свойство <strong><code>pushManager</code></strong> интерфейса {{domxref("ServiceWorkerRegistration")}} возвращает ссылку на интерфейс {{domxref("PushManager")}}, позволяющий управлять подписками на push-уведомления. Включает поддержку процедуры подписки, получения активной подписки, а также предоставляет доступ к стутусу разрешений на push-уведомления.</p> + +<h2 id="Syntax" name="Syntax" style="line-height: 30px; font-size: 2.14285714285714rem;">Синтакс</h2> + +<pre class="syntaxbox" style="font-size: 14px;">myPushManager = ServiceWorker.pushManager +</pre> + +<h3 id="Значение">Значение</h3> + +<p>Объект {{domxref("PushManager")}}.</p> + +<h2 id="Примеры">Примеры</h2> + +<pre class="brush: js">this.onpush = function(event) { + console.log(event.data); + // Отсюда можно записывать данные в IndexedDB, отправлять их в любое + // открытое окно, отображать уведомление и т. д. +} + +navigator.serviceWorker.register('serviceworker.js').then( + function(serviceWorkerRegistration) { + serviceWorkerRegistration.pushManager.subscribe().then( + function(pushSubscription) { + console.log(pushSubscription.subscriptionId); + console.log(pushSubscription.endpoint); + // Детали push-подписки, требуемые сервером приложения, + // теперь доступны, и могут быть отправлены, к примеру, + // при помощи XMLHttpRequest. + }, function(error) { + // При разработке это часто помогает отлавливать ошибки в консоли. + // В продакшен-среде это также может быть полезно для отправки отчета + // об ошибках на сервер приложения. + console.log(error); + } + ); + });</pre> + +<h2 id="Спецификации">Спецификации</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Push API', '#pushmanager-interface', 'PushManager')}}</td> + <td>{{Spec2('Push API')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Совместимость_с_браузерами">Совместимость с браузерами</h2> + + + +<p>{{Compat("api.ServiceWorkerRegistration.pushManager")}}</p> + +<h2 id="Смотрите_также">Смотрите также</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Push_API">Push API</a></li> +</ul> diff --git a/files/ru/web/api/serviceworkerregistration/shownotification/index.html b/files/ru/web/api/serviceworkerregistration/shownotification/index.html new file mode 100644 index 0000000000..fdcd0943fc --- /dev/null +++ b/files/ru/web/api/serviceworkerregistration/shownotification/index.html @@ -0,0 +1,272 @@ +--- +title: ServiceWorkerRegistration.showNotification() +slug: Web/API/ServiceWorkerRegistration/showNotification +translation_of: Web/API/ServiceWorkerRegistration/showNotification +--- +<p>{{SeeCompatTable}}{{APIRef("Service Workers API")}}</p> + +<p>The <code>showNotification()</code> method of the {{domxref("ServiceWorkerRegistration")}} interface creates a notification on an active service worker.</p> + +<div class="note"> +<p><strong>Note</strong>: This feature is available in <a href="/en-US/docs/Web/API/Web_Workers_API">Web Workers</a>.</p> +</div> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">ServiceWorkerRegistration.showNotification(<em>title</em>, [<em>options</em>]).then(function(<em>NotificationEvent</em>) { ... });</pre> + +<h3 id="Returns">Returns</h3> + +<p>A {{jsxref('Promise')}} that resolves to a {{domxref('NotificationEvent')}}.</p> + +<h3 id="Parameters">Parameters</h3> + +<dl> + <dt><code>title</code></dt> + <dd>The title that must be shown within the notification</dd> + <dt><code>options</code> {{optional_inline}}</dt> + <dd>An object that allows to configure the notification. It can have the following properties: + <ul> + <li><code>actions</code>: An array of actions to display in the notification. The members of the array should be an object literal. It may contain the following values: + <ul> + <li>action: A {{domxref("DOMString")}} identifying a user action to be displayed on the notification.</li> + <li>title: A {{domxref("DOMString")}} containing action text to be shown to the user.</li> + <li>icon: A {{domxref("USVString")}} containg the URL of an icon to display with the action.</li> + </ul> + Appropriate responses are built using <code>event.action</code> within the {{event("notificationclick")}} event.</li> + <li><code>badge</code>: The URL of an image to represent the notification when there is not enough space to display the notification itself such as, for example, the Android Notification Bar. On Android devices, the badge should accommodate devices up to 4x resolution, about 96 by 96 px, and the image will be automatically masked.</li> + <li><code>body</code>: Строка с дополнительным контентом уведомления.</li> + <li><code>dir</code> : The direction of the notification; it can be <code>auto</code>, <code>ltr</code>, or <code>rtl</code></li> + <li><code>icon</code>: URL или base64 версия картинки, которая отображается рядом с уведомлением.</li> + <li><code>image</code>: URL {{domxref("USVSTring")}} картинки, которая отображается внутри уведомления.</li> + <li><code>lang</code>: Specify the lang used within the notification. This string must be a valid <a href="http://tools.ietf.org/html/bcp47" title="http://tools.ietf.org/html/bcp47">BCP 47 language tag</a>.</li> + <li><code>renotify</code>: A boolean that indicates whether to supress vibrations and audible alerts when resusing a <code>tag</code> value. The default is false.</li> + <li><code>requireInteraction</code>: Indicates that on devices with sufficiently large screens, a notification should remain active until the user clicks or dismisses it. If this value is absent or false, the desktop version of Chrome will auto-minimize notifications after approximately twenty seconds. The default value is <code>false</code>.</li> + <li><code>tag</code>: An ID for a given notification that allows you to find, replace, or remove the notification using script if necessary.</li> + <li><code>vibrate</code>: Шаблон вибрации, которая будет воспроизведена вместе с уведомлением. Шаблон может быть массивом из как минимум одного элемента. Значения элементов это время в миллисекундах, при этом четные элементы (0, 2, 4, и т.д.) отражают периоды вибрации, а нечетные периоды пауз. Например, <code>[300, 100, 400]</code> будет означать вибрацию 300ms, паузу 100ms, затем вибрацию 400ms.</li> + <li><code>data</code>: Arbitrary data that you want associated with the notification. This can be of any data type.</li> + </ul> + </dd> +</dl> + +<h2 id="Examples">Examples</h2> + +<pre class="brush: js">navigator.serviceWorker.register('sw.js'); + +function showNotification() { + Notification.requestPermission(function(result) { + if (result === 'granted') { + navigator.serviceWorker.ready.then(function(registration) { + registration.showNotification('Vibration Sample', { + body: 'Buzz! Buzz!', + icon: '../images/touch/chrome-touch-icon-192x192.png', + vibrate: [200, 100, 200, 100, 200, 100, 200], + tag: 'vibration-sample' + }); + }); + } + }); +}</pre> + +<p>To invoke the above function at an appropriate time, you could use the {{domxref("ServiceWorkerGlobalScope.onnotificationclick")}} event handler.</p> + +<p>You can also retrieve details of the {{domxref("Notification")}}s have have been fired from the current service worker using {{domxref("ServiceWorkerRegistration.getNotifications()")}}.</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Web Notifications','#dom-serviceworkerregistration-shownotificationtitle-options','showNotification()')}}</td> + <td>{{Spec2('Web Notifications')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.ServiceWorkerRegistration.showNotification")}}</p> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td><code>vibrate</code> option</td> + <td>{{CompatChrome(45)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatOpera(32)}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>requireInteraction</code></td> + <td>{{CompatChrome(47)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>actions</code> option</td> + <td>{{CompatChrome(48)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>renotify</code> option</td> + <td>{{CompatChrome(50)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatOpera(37)}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>badge</code> option</td> + <td>{{CompatChrome(53)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatOpera(39)}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>image</code> option</td> + <td>{{CompatChrome(56)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>data</code> option</td> + <td>{{CompatChrome(44)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Android Webview</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td><code>vibrate</code> option</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatOperaMobile(32)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatChrome(45)}}</td> + </tr> + <tr> + <td><code>requireInteraction</code></td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatChrome(47)}}</td> + </tr> + <tr> + <td><code>actions</code> option</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatChrome(48)}}</td> + </tr> + <tr> + <td><code>renotify</code> option</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatOperaMobile(37)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatChrome(50)}}</td> + </tr> + <tr> + <td><code>badge</code> option</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatOperaMobile(39)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatChrome(53)}}</td> + </tr> + <tr> + <td><code>image</code> option</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatChrome(56)}}</td> + </tr> + <tr> + <td><code>data</code> option</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(44)}}</td> + </tr> + </tbody> +</table> +</div> diff --git a/files/ru/web/api/serviceworkerregistration/update/index.html b/files/ru/web/api/serviceworkerregistration/update/index.html new file mode 100644 index 0000000000..5a2180581a --- /dev/null +++ b/files/ru/web/api/serviceworkerregistration/update/index.html @@ -0,0 +1,74 @@ +--- +title: ServiceWorkerRegistration.update() +slug: Web/API/ServiceWorkerRegistration/update +translation_of: Web/API/ServiceWorkerRegistration/update +--- +<div>{{SeeCompatTable}}{{APIRef("Service Workers API")}}</div> + +<p>Метод <code><strong>update</strong></code> интерфейса {{domxref("ServiceWorkerRegistration")}} предназначен для обновления service worker. Он обращаетя по URL service worker-a, и если новый worker побайтно не совпадает с текущим, инсталирует новую версию. Обращение за новой версией worker обходит любые кеши браузера, если предыдущее обращение произошло более 24 часов назад..</p> + +<div class="note"> +<p><strong>Заметка</strong>: Эта возможность доступна в <a href="/en-US/docs/Web/API/Web_Workers_API">Web Workers</a>.</p> +</div> + +<h2 id="Syntax" name="Syntax" style="line-height: 30px; font-size: 2.14285714285714rem;">Синтаксис</h2> + +<pre class="syntaxbox" style="font-size: 14px;">ServiceWorkerRegistration.update();</pre> + +<h3 id="Параметры">Параметры</h3> + +<p>Нет.</p> + +<h3 id="Возвращает">Возвращает</h3> + +<p>{{domxref("Промис")}}, который разрешается в объект {{domxref("ServiceWorkerRegistration")}}.</p> + +<h2 id="Пример">Пример</h2> + +<p>В следующем простом примере регистрируется service worker, а затем добавляется обработчик события клика по кнопке, так что вы можете явно обновить service worker по необходимости:</p> + +<pre class="brush: js">if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/sw-test/sw.js', {scope: 'sw-test'}).then(function(registration) { + // Регистрация произошла + console.log('Registration succeeded.'); + button.onclick = function() { + registration.update(); + } + }).catch(function(error) { + // Ошибка при регистрации + console.log('Registration failed with ' + error); + }); +};</pre> + +<h2 id="Спецификации">Спецификации</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Спецификация</th> + <th scope="col">Статус</th> + <th scope="col">Комментарий</th> + </tr> + <tr> + <td>{{SpecName('Service Workers', '#service-worker-registration-update-method', 'ServiceWorkerRegistration.update()')}}</td> + <td>{{Spec2('Service Workers')}}</td> + <td>Первоначальное определение.</td> + </tr> + </tbody> +</table> + +<h2 id="Совместимость_с_браузерами">Совместимость с браузерами</h2> + +<div class="hidden">Таблица совместимости на этой странице сгенерирована автоматически. Если вы хотите внести свой вклад в таблицу данных совместимости, пожалуйста обратитесь по адресу <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> и сделайте pull request.</div> + +<p>{{Compat("api.ServiceWorkerRegistration.update")}}</p> + +<h2 id="Смотрите_также">Смотрите также</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/ServiceWorker_API/Using_Service_Workers">Использование Service Workers</a></li> + <li><a href="https://github.com/mdn/sw-test">Service workers базовый пример кода</a> </li> + <li><a href="https://jakearchibald.github.io/isserviceworkerready/">Готов ли ServiceWorker?</a></li> + <li>{{jsxref("Промисы")}}</li> + <li><a href="/en-US/docs/Web/Guide/Performance/Using_web_workers">Использование web workers</a></li> +</ul> |
