From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/ja/web/api/serviceworker/index.html | 113 ++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 files/ja/web/api/serviceworker/index.html (limited to 'files/ja/web/api/serviceworker/index.html') diff --git a/files/ja/web/api/serviceworker/index.html b/files/ja/web/api/serviceworker/index.html new file mode 100644 index 0000000000..78f43d1c67 --- /dev/null +++ b/files/ja/web/api/serviceworker/index.html @@ -0,0 +1,113 @@ +--- +title: ServiceWorker +slug: Web/API/ServiceWorker +tags: + - API + - Draft + - Interface + - Offline + - Service Workers + - ServiceWorker + - Workers +translation_of: Web/API/ServiceWorker +--- +
{{SeeCompatTable}}{{APIRef("Service Workers API")}}
+ +

ServiceWorker API のインターフェイスである ServiceWorker は service worker に関するレファレンスを提供しています。様々なブラウザー環境(例えばページ、worker など)が同一の service worker に関連付けることができて、一意な ServiceWorker オブジェクト​からアクセスできます。 

+ +

ServiceWorker オブジェクトはプロバティ{{domxref("ServiceWorkerRegistration.active")}}と{{domxref("ServiceWorkerContainer.controller")}}プロパティ — これは起動された service worker でページを管理しています (そのservice workerが正常に登録されて管理されるページがリロードされています) — の中で利用可能です。

+ +

ServiceWorker インターフェイスへは、 installactivate 、そして fetch を含む機能的なイベントといったライフサイクルイベントのセットが送られます。ServiceWorker オブジェクトは、ライフサイクルに関係する {{domxref("ServiceWorker.state")}} (状態) を持っています。

+ +

プロパティ

+ +

ServiceWorker インターフェイスは親となる{{domxref("Worker")}}からプロパティを継承します。

+ +
+
{{domxref("ServiceWorker.scriptURL")}} {{readonlyinline}}
+
+

{{domxref("ServiceWorkerRegistration")}}の一部と定義されたスクリプト URL にシリアライズされた ServiceWorker を返します。この URL はその ServiceWorker を登録している document と同一オリジン上でなければなりません。

+
+
{{domxref("ServiceWorker.state")}} {{readonlyinline}}
+
service worker の状態を返します。installing, installedactivating, activatedredundant のいずれかの値を返します。
+
+ +

イベントハンドラ

+ +
+
{{domxref("ServiceWorker.onstatechange")}} {{readonlyinline}}
+
statechange イベントが発火した際に呼び出される{{domxref("EventListener")}} プロパティです。このイベントは {{domxref("ServiceWorker.state")}} が変更された際に発火されます。
+
+ +

メソッド

+ +

ServiceWorker インターフェイスは親である{{domxref("Worker")}}インターフェイスからメソッドを継承していますが、{{domxref("Worker.terminate")}} は例外です。このメソッドは service worker からアクセスされるべきではありません。

+ +

+ +

このコードスニペットは service worker registration-events sample (live demo)の一部です。{{domxref("ServiceWorker.state")}} のあらゆる変更をリッスンし、その値を返します。

+ +
if ('serviceWorker' in navigator) {
+    navigator.serviceWorker.register('service-worker.js', {
+        scope: './'
+    }).then(function (registration) {
+        var serviceWorker;
+        if (registration.installing) {
+            serviceWorker = registration.installing;
+            document.querySelector('#kind').textContent = 'installing';
+        } else if (registration.waiting) {
+            serviceWorker = registration.waiting;
+            document.querySelector('#kind').textContent = 'waiting';
+        } else if (registration.active) {
+            serviceWorker = registration.active;
+            document.querySelector('#kind').textContent = 'active';
+        }
+        if (serviceWorker) {
+            // logState(serviceWorker.state);
+            serviceWorker.addEventListener('statechange', function (e) {
+                // logState(e.target.state);
+            });
+        }
+    }).catch (function (error) {
+        // Something went wrong during registration. The service-worker.js file
+        // might be unavailable or contain a syntax error.
+    });
+} else {
+    // The current browser doesn't support service workers.
+}
+ +

仕様

+ + + + + + + + + + + + + + +
仕様書策定状況コメント
{{SpecName('Service Workers', '#service-worker-obj', 'ServiceWorker')}}{{Spec2('Service Workers')}}初期定義
+ +

ブラウザー実装状況

+ +
+ + +

{{Compat("api.ServiceWorker")}}

+
+ +

関連

+ + -- cgit v1.2.3-54-g00ecf