이 번역은 완료되지 않았습니다. 이 문서를 번역해 주세요.

Push API는 웹 애플리케이션이 현재 로딩이 되어 있지 않더라도 서버로부터 메시지를 받을 수 있도록 하는 기능이다. 이는 개발자들이 비동기적으로 사용자에게 새로운 내용을 시기적절하게 전달할 수 있도록 만들어 준다.

Push 콘셉트와 사용처

PushManager를 수행할 때,  해당 애플리케이션에 CSRF/XSRF 이슈에 대한 대응책을 마련해놓아야 한다: 

애플리케이션이 push 메시지를 받기 위해서, service worker를 활성화한다. 

PushManager.subscribe().

PushSubscription에 애플리케이션이 보내야 하는 push메시지를 담고, (엔드포인트와 암호화키가 필요)

service worker는ServiceWorkerGlobalScope.onpush 라는 이벤트 핸들러로부터 전달되는 push 메시지를 처리하기 시작한다.

각 요청은 capability URL:(당신의 애플리케이션)을 특정하여 엔드포인트를 구성하기 때문에 엔드포인트 URL은 보안에 신경을 써야 하며, 그렇지 않을 경우 다른 애플리케이션에서 당신의 애플리케이션에 push 메시지를 보낼 가능성도 있다. 

push 메시지를 전달하기 위해 service worker를 활성화하는 건, 리소스 사용이 늘어나는 결과를 가져오기 때문에, 특히 배터리 사용에 영향을 미친다. 한편 push메시지 처리를 위해 브라우저 간 다른 스키마를 가지기 때문에, 표준화된 메커니즘이 없다. Firefox는 한정된 숫자(quota)만을 push 메시지로 보내도록 해 놓았다. 이러한 제한은 사이트에 방문할 때마다 초기화되며, Chrome은 제한이 없으며 모든 push 메시지가 보이도록 한다. 

Note: Gecko 44에 따르면, 각 애플리케이션에 할당된 quota는 3초 정도 다른 알림이 보이는 상태일 때, 새로운 알림이 발생해도 중가하지 않는다. 

Note: Chrome 52 이전 버전은 push메시지 활용을 위해선 Google Cloud Messaging에 프로젝트를 세팅해야 하며 한편 push 메시지를 보낼 때 프로젝트 번호 및 API 키를 활용하도록 권장한다. app manifest에 서비스 활용에 필요한 특정 패러미터를 정의해야 한다.

Interfaces

PushEvent
Represents a push action, sent to the global scope of a ServiceWorker. It contains information sent from an application to a PushSubscription.
PushManager
Provides a way to receive notifications from third-party servers, as well as request URLs for push notifications. This interface has replaced the functionality offered by the obsolete PushRegistrationManager interface.
PushMessageData
Provides access to push data sent by a server, and includes methods to manipulate the received data.
PushSubscription
Provides a subcription's URL endpoint, and allows unsubscription from a push service.

Service worker additions

The following additions to the Service Worker API have been specified in the Push API spec to provide an entry point for using Push messages. They also monitor and respond to push and subscription change events.

ServiceWorkerRegistration.pushManager Read only
Returns a reference to the PushManager interface for managing push subscriptions including subscribing, getting an active subscription, and accessing push permission status. This is the entry point into using Push messaging.
ServiceWorkerGlobalScope.onpush
An event handler fired whenever a push event occurs; that is, whenever a server push message is received.
ServiceWorkerGlobalScope.onpushsubscriptionchange
An event handler fired whenever a pushsubscriptionchange event occurs; for example, when a push subscription has been invalidated, or is about to be invalidated (e.g. when a push service sets an expiration time.)

Examples

Mozilla's ServiceWorker Cookbook contains many useful Push examples.

Specifications

Specification Status Comment
Push API Working Draft Initial definition

Browser compatibility

PushEvent

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
PushEvent
Experimental
Chrome Full support 42Edge Full support 16
Disabled
Full support 16
Disabled
Disabled From version 16: this feature is behind the Enable service workers preference.
Full support 17
Firefox Full support 44
Notes
Full support 44
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 and 52 Extended Support Releases (ESR.)
Notes Enabled only in Nightly, Developer Edition, and Beta channels.
IE No support NoOpera Full support 37Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 44
Full support 44
Full support 48
Notes
Notes Push enabled by default.
Opera Android Full support 37Safari iOS No support NoSamsung Internet Android Full support 4.0
PushEvent() constructor
Experimental
Chrome Full support 42Edge Full support 16
Disabled
Full support 16
Disabled
Disabled From version 16: this feature is behind the Enable service workers preference.
Full support 17
Firefox Full support 44
Notes
Full support 44
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 and 52 Extended Support Releases (ESR.)
Notes Enabled only in Nightly, Developer Edition, and Beta channels.
IE No support NoOpera Full support 37Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 44
Full support 44
Full support 48
Notes
Notes Push enabled by default.
Opera Android Full support 37Safari iOS No support NoSamsung Internet Android Full support 4.0
data
Experimental
Chrome Full support 57Edge Full support 16
Disabled
Full support 16
Disabled
Disabled From version 16: this feature is behind the Enable service workers preference.
Full support 17
Firefox Full support 44
Notes
Full support 44
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 and 52 Extended Support Releases (ESR.)
Notes Enabled only in Nightly, Developer Edition, and Beta channels.
IE No support NoOpera Full support 44Safari No support NoWebView Android No support NoChrome Android Full support 57Firefox Android Full support 44
Full support 44
Full support 48
Notes
Notes Push enabled by default.
Opera Android Full support 43Safari iOS No support NoSamsung Internet Android Full support 4.0

Legend

Full support  
Full support
No support  
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

PushMessageData

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
PushMessageData
Experimental
Chrome Full support 50Edge ? Firefox Full support 44
Notes
Full support 44
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
IE No support NoOpera Full support 37Safari No support NoWebView Android No support NoChrome Android Full support 50Firefox Android Full support 48Opera Android Full support 37Safari iOS No support NoSamsung Internet Android Full support 5.0
arrayBuffer
Experimental
Chrome Full support 50Edge ? Firefox Full support 44
Notes
Full support 44
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
IE No support NoOpera Full support 37Safari No support NoWebView Android No support NoChrome Android Full support 50Firefox Android Full support 48Opera Android Full support 37Safari iOS No support NoSamsung Internet Android Full support 5.0
blob
Experimental
Chrome Full support 50Edge ? Firefox Full support 44
Notes
Full support 44
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
IE No support NoOpera Full support 37Safari No support NoWebView Android No support NoChrome Android Full support 50Firefox Android Full support 48Opera Android Full support 37Safari iOS No support NoSamsung Internet Android Full support 5.0
json
Experimental
Chrome Full support 50Edge ? Firefox Full support 44
Notes
Full support 44
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
IE No support NoOpera Full support 37Safari No support NoWebView Android No support NoChrome Android Full support 50Firefox Android Full support 48Opera Android Full support 37Safari iOS No support NoSamsung Internet Android Full support 5.0
text
Experimental
Chrome Full support 50Edge ? Firefox Full support 44
Notes
Full support 44
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
IE No support NoOpera Full support 37Safari No support NoWebView Android No support NoChrome Android Full support 50Firefox Android Full support 48Opera Android Full support 37Safari iOS No support NoSamsung Internet Android Full support 5.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.

See also

문서 태그 및 공헌자

이 페이지의 공헌자: younheeJang
최종 변경자: younheeJang,