webKit를 사용한 리치 알림

풍부한 데스크톱 알림을 사용하여 사용자에게 중요한 일이 발생했음을 알립니다. 알림은 브라우저 창 외부에 표시됩니다. 다음 스냅샷에 나와 있는 것처럼 알림의 모양과 표시 위치에 관한 세부정보는 플랫폼에 따라 다릅니다.

Microsoft Windows의 알림

Mac OS X의 알림

Ubuntu Linux의 알림

약간의 JavaScript와 확장 프로그램 내에 패키징된 HTML 페이지(선택사항)를 사용하여 알림 창을 만듭니다.

먼저 매니페스트에서 notifications 권한을 선언합니다.

{
  "name": "My extension",
  "manifest_version": 2,
  ...
  "permissions": [
    "notifications"
  ],
  ...
  // Note: Because of bug 134315, you must declare any images you
  // want to use with createNotification() as a web accessible resource.
  "web_accessible_resources": [
    "48.png"
  ],
}

그런 다음 webkitNotifications 객체를 사용하여 알림을 만듭니다.

// Note: There's no need to call webkitNotifications.checkPermission().
// Extensions that declare the notifications permission are always
// allowed create notifications.

// Create a simple text notification:
var notification = webkitNotifications.createNotification(
  '48.png',  // icon url - can be relative
  'Hello!',  // notification title
  'Lorem ipsum...'  // notification body text
);

// Or create an HTML notification:
var notification = webkitNotifications.createHTMLNotification(
  'notification.html'  // html url - can be relative
);

// Then show the notification.
notification.show();

API 참조

데스크톱 알림 초안 사양을 참조하세요.

다른 뷰와 통신

extension.getBackgroundPageextension.getViews를 사용하여 확장 프로그램에서 알림과 다른 뷰 간에 통신할 수 있습니다. 예를 들면 다음과 같습니다.

chrome.extension.getBackgroundPage().doThing();
chrome.extension.getViews({type:"notification"}).forEach(function(win) {
  win.doOtherThing();
});

예시 더보기

examples/api/notifications 디렉터리에서 알림 사용의 간단한 예를 확인할 수 있습니다. 다른 예와 소스 코드 보기에 대한 도움말은 샘플을 참조하세요.

html5rocks.com의 알림 가이드도 참조하세요. 권한 관련 코드는 무시합니다. '알림' 권한을 선언하는 경우에는 필요하지 않습니다.