From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- files/ko/web/api/serviceworker/index.html | 113 +++++++++++++++++++++ .../web/api/serviceworker/onstatechange/index.html | 72 +++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 files/ko/web/api/serviceworker/index.html create mode 100644 files/ko/web/api/serviceworker/onstatechange/index.html (limited to 'files/ko/web/api/serviceworker') diff --git a/files/ko/web/api/serviceworker/index.html b/files/ko/web/api/serviceworker/index.html new file mode 100644 index 0000000000..e7e5907ecf --- /dev/null +++ b/files/ko/web/api/serviceworker/index.html @@ -0,0 +1,113 @@ +--- +title: ServiceWorker +slug: Web/API/ServiceWorker +tags: + - API + - Interface + - Offline + - Reference + - Service Workers + - ServiceWorker + - Workers + - 서비스 워커 + - 워커 +translation_of: Web/API/ServiceWorker +--- +
{{APIRef("Service Workers API")}}
+ +

Service Worker APIServiceWorker 인터페이스는 서비스 워커로의 참조를 제공합니다. 다수의{{glossary("browsing context", "브라우징 맥락")}}(e.g. 페이지, 다른 워커, 등등)는 고유한 ServiceWorker 객체를 통해 동일한 서비스 워커와 연결할 수 있습니다.

+ +

ServiceWorker 객체는 {{domxref("ServiceWorkerRegistration.active")}} 속성과 {{domxref("ServiceWorkerContainer.controller")}} 속성으로 접근할 수 있습니다. controller는 활성화되어 페이지를 통제 중인 서비스 워커입니다.

+ +

ServiceWorker 인터페이스에서는 일련의 생명주기 이벤트(install, activate)와 기능 이벤트(fetch)가 발생합니다. ServiceWorker 객체의 생명주기는 {{domxref("ServiceWorker.state")}} 속성이 담고 있습니다.

+ +

속성

+ +

ServiceWorker 인터페이스는 부모 {{domxref("Worker")}}에서 속성을 상속합니다.

+ +
+
{{domxref("ServiceWorker.scriptURL")}} {{readonlyinline}}
+
Returns the ServiceWorker serialized script URL defined as part of {{domxref("ServiceWorkerRegistration")}}. The URL must be on the same origin as the document that registers the ServiceWorker.
+
{{domxref("ServiceWorker.state")}} {{readonlyinline}}
+
Returns the state of the service worker. It returns one of the following values: installing, installed, activating, activated, or redundant.
+
+ +

이벤트 처리기

+ +
+
{{domxref("ServiceWorker.onstatechange")}} {{readonlyinline}}
+
An {{domxref("EventListener")}} property called whenever an event of type statechange is fired; it is basically fired anytime the {{domxref("ServiceWorker.state")}} changes.
+
+ +

메서드

+ +

ServiceWorker 인터페이스는 부모 {{domxref("Worker")}}에서 메서드를 상속합니다. 단, {{domxref("Worker.terminate()")}}는 예외이며 서비스 워커에서 접근할 수 없습니다.

+ +

예제

+ +

This code snippet is from the service worker registration-events sample (live demo). The code listens for any change in the {{domxref("ServiceWorker.state")}} and returns its value.

+ +
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.
+}
+ +

명세

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Service Workers', '#serviceworker', 'ServiceWorker')}}{{Spec2('Service Workers')}}Initial definition.
+ +

브라우저 호환성

+ +
+ + +

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

+
+ +

같이 보기

+ + diff --git a/files/ko/web/api/serviceworker/onstatechange/index.html b/files/ko/web/api/serviceworker/onstatechange/index.html new file mode 100644 index 0000000000..d6063f0445 --- /dev/null +++ b/files/ko/web/api/serviceworker/onstatechange/index.html @@ -0,0 +1,72 @@ +--- +title: ServiceWorker.onstatechange +slug: Web/API/ServiceWorker/onstatechange +translation_of: Web/API/ServiceWorker/onstatechange +--- +
{{SeeCompatTable}}{{APIRef("Service Workers API")}}
+ +

statechange 타입의 이벤트가 발생될 때마다 호출되는 {{domxref("EventListener")}} 속성. 기본적으로 {{domxref("ServiceWorker.state")}}가 변경되는 시점에 발생한다.

+ +

Syntax

+ +
ServiceWorker.onstatechange = function(statechangeevent) { ... }
+ServiceWorker.addEventListener('statechange', function(statechangeevent) { ... } )
+ +

Examples

+ +

이 코드 조각은 service worker registration-events sample (live demo) 으로부터 가져온 것이다. 이 코드는 {{domxref("ServiceWorker.state")}}의 모든 변경 사항을 수신하고 그 값을 반환한다.

+ +
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);
+  });
+}
+ +

statechange 가 발생할 때, 서비스워커의 참조들이 변화할 수 있으므로 주의하라. 예시:

+ +
navigator.serviceWorker.register(..).then(function(swr) {
+  swr.installing.state == "installing"
+  swr.installing.onstatechange = function() {
+    swr.installing == null;
+    // 이 시점에서, swr.waiting 또는 swr.active는 true일 것이다. 이것은 statechange 이벤트가 대기 상태이기 때문이며,
+    // 그동안 잠재 상태의 워커가 waiting 상태가 될 수도 있으며 가능한 경우에는 즉시 activated 될 것이다.
+  }
+})
+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Service Workers', '#service-worker-onstatechange-attribute', 'ServiceWorker.onstatechange')}}{{Spec2('Service Workers')}}Initial definition
+ +

Browser compatibility

+ +
+ + +

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

+
-- cgit v1.2.3-54-g00ecf