Remove notification permission from push cookbook sample (#1365)

* Remove notification permission from push cookbook sample

As of [M132] this requirement is no longer necessary (unless the extension chooses to show a notification).

[M132]: https://chromiumdash.appspot.com/commit/ed68ac786e9a276ef2b627b7e21cf0d20cc6d798

* address review comments

* Add note about minimum Chrome version

---------

Co-authored-by: Oliver Dunk <oliverdunk@google.com>
This commit is contained in:
Justin Lulejian
2024-12-24 16:08:12 -05:00
committed by GitHub
parent 600017fca8
commit 5064031481
3 changed files with 7 additions and 6 deletions

View File

@@ -4,12 +4,13 @@ This sample demonstrates using the [Push API](https://developer.mozilla.org/en-U
## Overview
By calling a method in the sample and using an external push server website we can simulate an extension receiving a push message where it is required to emit a notification and where it can bypass that requirement (`userVisibleOnly = false`).
By calling a method in the sample and using an external push server website we can simulate an extension receiving a push message where it is not required to emit a notification by setting (`userVisibleOnly = false`) on registration.
## Running this extension
Note: This sample requires Chrome 132+. Before Chrome 132, the same code works with the additional requirement of the `notification` extension permission.
1. Clone this repository.
1. Ensure your operating system allows your browser to show desktop notification. For [MacOS](https://support.apple.com/guide/mac-help/change-notifications-settings-mh40583/mac) this, for Google Chrome, requires "Google Chrome" and "Google Chrome Helper (Alerts)" to be allowed.
1. Go to the [web push test server](https://web-push-codelab.glitch.me/) and copy the “Public Key” to the `APPLICATION_SERVER_PUBLIC_KEY` variable in background.js.
1. Load this directory in Chrome as an [unpacked extension](https://developer.chrome.com/docs/extensions/mv3/getstarted/development-basics/#load-unpacked).
1. Click “service worker (Inactive)” on the extension to load DevTools for background.js

View File

@@ -56,7 +56,8 @@ self.addEventListener('push', function (event) {
);
// Before `userVisibleOnly` could be passed as false we would have to show a
// notification at this point, but now we no longer have to.
// notification at this point (or if we didn't the browser would show a
// generic notification), but now we no longer have to.
});
// Helper method for converting the server key to an array that is passed

View File

@@ -1,9 +1,8 @@
{
"name": "Service worker with push notification",
"name": "Service worker with silent push message",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"permissions": ["notifications"]
}
}