Content update & fix of Notification in Service Worker#32099
Content update & fix of Notification in Service Worker#32099
Conversation
|
Preview URLs
External URLs (2)URL:
(comment last updated: 2024-02-09 06:15:03) |
| - `title` | ||
| - : A string containing action text to be shown to the user. | ||
| - `icon` | ||
| - `icon` {{optional_inline}} |
There was a problem hiding this comment.
Flyby. If the parent is optional, aren't all of the sub items (i.e why not action and title too)? Or are you saying that IFF actions is specified, then the action and title must be specified, but icon is optional?
There was a problem hiding this comment.
IFF actions is specified, then the action and title must be specified, but icon is optional?
Basically, yes:
optionsis optional (https://notifications.spec.whatwg.org/#service-worker-api)optionshas an optional attributeactions(https://notifications.spec.whatwg.org/#dictdef-notificationoptions)actionsis an array ofNotificationActionobjects, which have mandatoryactionandtitleproperties, and an optionaliconproperty (https://notifications.spec.whatwg.org/#dictdef-notificationaction)
There was a problem hiding this comment.
Although weirdly it seems as if, if you call this constructor, you must not pass any actions, or you get a TypeError exception? https://notifications.spec.whatwg.org/#create-a-notification
There was a problem hiding this comment.
Thanks.
Although weirdly it seems as if, if you call this constructor, you must not pass any actions, or you get a TypeError exception? https://notifications.spec.whatwg.org/#create-a-notification
It says "If a serviceWorkerRegistration was not provided and options["actions"] is not empty, then throw a TypeError."
So you you can only have actions if the serviceworker registration is provided.
Looking through this there are lots of missing cases that can throw a typerror
There was a problem hiding this comment.
So you you can only have actions if the serviceworker registration is provided.
Right, but that operation I linked, https://notifications.spec.whatwg.org/#create-a-notification , can I think be reached from two paths:
- calling the
Notification()constructor (https://notifications.spec.whatwg.org/#ref-for-create-a-notification) - calling
ServiceWorkerRegistration.showNotification()(https://notifications.spec.whatwg.org/#ref-for-create-a-notification%E2%91%A0)
...and it's only in the second of these cases that the registration gets passed. So if you call the constructor, you must not provide actions.
There was a problem hiding this comment.
Right, but that operation I linked, https://notifications.spec.whatwg.org/#create-a-notification , can I think be reached from two paths:
- calling the
Notification()constructor (https://notifications.spec.whatwg.org/#ref-for-create-a-notification)- calling
ServiceWorkerRegistration.showNotification()(https://notifications.spec.whatwg.org/#ref-for-create-a-notification%E2%91%A0)...and it's only in the second of these cases that the registration gets passed. So if you call the constructor, you must not provide actions.
yes, actions parameter can not use with Notification() constructor
| - `title` | ||
| - : A string containing action text to be shown to the user. | ||
| - `icon` | ||
| - `icon` {{optional_inline}} |
There was a problem hiding this comment.
Although weirdly it seems as if, if you call this constructor, you must not pass any actions, or you get a TypeError exception? https://notifications.spec.whatwg.org/#create-a-notification
files/en-us/web/api/notifications_api/using_the_notifications_api/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/api/notifications_api/using_the_notifications_api/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/api/serviceworkerglobalscope/notificationclick_event/index.md
Outdated
Show resolved
Hide resolved
Co-authored-by: wbamberg <will@bootbonnet.ca>
…_event/index.md Co-authored-by: wbamberg <will@bootbonnet.ca>
…louds2001/content into notification-service-worker
Description
move the note in
ServiceWorkerGlobalScope.notificationcloseevent toNotification()constructorand update content indicating relative event on
NotificationinServiceWorkerGlobalScope.notificationclickalso update example description by replacing event handler property usage to event
Motivation
Additional details
Related issues and pull requests