Skip to content

Instantly share code, notes, and snippets.

View beverloo's full-sized avatar

Peter Beverloo beverloo

View GitHub Profile
self.addEventListener('push', async(e) => {
const notification = await fetch(e.data.text()); // payload contains a URL
await registration.showNotification(notification.title, {
body: notification.body,
icon: notification.icon
});
});
diff --git a/chrome/browser/push_messaging/push_messaging_browsertest.cc b/chrome/browser/push_messaging/push_messaging_browsertest.cc
index 2543d79d..ffa3179 100644
--- a/chrome/browser/push_messaging/push_messaging_browsertest.cc
+++ b/chrome/browser/push_messaging/push_messaging_browsertest.cc
@@ -901,6 +901,8 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile())
->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING);
+ HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile())
+ ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
diff --git a/chrome/browser/push_messaging/push_messaging_permission_context.cc b/chrome/browser/push_messaging/push_messaging_permission_context.cc
index 6125f3e..bd774dd 100644
--- a/chrome/browser/push_messaging/push_messaging_permission_context.cc
+++ b/chrome/browser/push_messaging/push_messaging_permission_context.cc
@@ -53,12 +53,11 @@ ContentSetting PushMessagingPermissionContext::GetPermissionStatus(
push_content_setting == CONTENT_SETTING_BLOCK) {
return CONTENT_SETTING_BLOCK;
}
- if (notifications_permission == CONTENT_SETTING_ASK ||
- push_content_setting == CONTENT_SETTING_ASK) {
@beverloo
beverloo / subscribe.js
Created December 2, 2015 14:22
PushSubscription - transmitting information to your server
navigator.serviceWorker.ready.then(registration => {
// Note that userVisibleOnly is not required for payloads - it's (still)
// required for Chrome's implementation though.
registration.pushManager.subscribe({ userVisibleOnly: true }).then(subscription => {
// Option 1: Using JSON.stringify() (recommended).
//
// The created JSON will have the following structure:
// { "endpoint": "https://...",
// "keys": {
// "p256dh": "...", // base64url encoded uncompressed P-256 EC point