PushManager

Push APIPushManager 인터페이스는 서드파티 서버에서 알림을 수신하거나, URL에 푸시 알림을 요청하는 방법을 제공합니다.

PushManagerServiceWorkerRegistration.pushManager 속성으로 접근할 수 있습니다.

속성

PushManager.supportedContentEncodings
푸시 메시지의 페이로드를 암호화할 때 지원하는 콘텐츠 인코딩의 목록을 반환합니다.

메서드

PushManager.getSubscription()
기존의 푸시 구독을 가져옵니다. 해당 구독에 대한 상세 정보를 담은 PushSubscription 객체를 Promise로 반환합니다. 구독이 존재하지 않으면 프로미스는 null로 이행합니다.
PushManager.permissionState()
PushManager의 허가 상태로 이행하는 Promise를 반환합니다. 상태는 'granted', 'denied', 'prompt' 중 하나입니다.
PushManager.subscribe()
푸시 서비스에 구독합니다. 해당 구독에 대한 상세 정보를 담은 PushSubscription 객체를 Promise로 반환합니다. 현재 서비스 워커에 이전 구독이 존재하지 않으면 새로운 푸시 구독을 생성합니다.

예제

this.onpush = function(event) {
  console.log(event.data);
  // From here we can write the data to IndexedDB, send it to any open
  // windows, display a notification, etc.
}

navigator.serviceWorker.register('serviceworker.js').then(
  function(serviceWorkerRegistration) {
    serviceWorkerRegistration.pushManager.subscribe().then(
      function(pushSubscription) {
        console.log(pushSubscription.endpoint);
        // The push subscription details needed by the application
        // server are now available, and can be sent to it using,
        // for example, an XMLHttpRequest.
      }, function(error) {
        // During development it often helps to log errors to the
        // console. In a production environment it might make sense to
        // also report information about errors back to the
        // application server.
        console.log(error);
      }
    );
  });

명세

Specification Status Comment
Push API
The definition of 'PushManager' in that specification.
Working Draft Initial definition.

브라우저 호환성

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
PushManager
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 Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support 29Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 48
Notes
Full support 48
Notes
Notes Push enabled by default.
Opera Android Full support 29Safari iOS No support NoSamsung Internet Android Full support 4.0
getSubscription
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 Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support 29Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 48
Notes
Full support 48
Notes
Notes Push enabled by default.
Opera Android Full support 29Safari iOS No support NoSamsung Internet Android Full support 4.0
hasPermission
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 Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support 29Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 48
Notes
Full support 48
Notes
Notes Push enabled by default.
Opera Android Full support 29Safari iOS No support NoSamsung Internet Android Full support 4.0
permissionState
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 Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support 29Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 48
Notes
Full support 48
Notes
Notes Push enabled by default.
Opera Android Full support 29Safari iOS No support NoSamsung Internet Android Full support 4.0
register
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 Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support 29Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 48
Notes
Full support 48
Notes
Notes Push enabled by default.
Opera Android Full support 29Safari iOS No support NoSamsung Internet Android Full support 4.0
registrations
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 Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support 29Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 48
Notes
Full support 48
Notes
Notes Push enabled by default.
Opera Android Full support 29Safari iOS No support NoSamsung Internet Android Full support 4.0
subscribe
Experimental
Chrome Full support 42
Notes
Full support 42
Notes
Notes The options parameter with a applicationServerKey value is required.
Edge 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 Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
Notes From Firefox 72 onwards, can only be called in response to a user gesture such as a click event.
IE No support NoOpera Full support 29Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 48
Notes
Full support 48
Notes
Notes Push enabled by default.
Opera Android Full support 29Safari iOS No support NoSamsung Internet Android Full support 4.0
supportedContentEncodings
Experimental
Chrome Full support 60Edge 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 Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support 47Safari No support NoWebView Android No support NoChrome Android Full support 60Firefox Android Full support 48
Notes
Full support 48
Notes
Notes Push enabled by default.
Opera Android Full support 44Safari iOS No support NoSamsung Internet Android Full support 4.0
unregister
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 Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support 29Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 48
Notes
Full support 48
Notes
Notes Push enabled by default.
Opera Android Full support 29Safari 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.

같이 보기