Skip to content

Commit 62ace36

Browse files
FluorescentHallucinogentoji
authored andcommitted
Notification multiple actions
1 parent 4a272e9 commit 62ace36

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

service-worker.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ self.addEventListener('notificationclick', (event) => {
77

88
if (!event.action) {
99
event.waitUntil(clients.openWindow(event.notification.data.url));
10+
return;
1011
}
12+
13+
console.log('Action ID:', event.action);
14+
console.log('Reply text:', event.reply);
1115
});

tests/permission-request.html

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@
7676
const title = 'Notification title';
7777

7878
const options = {
79-
body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
79+
body: `This notification can have a maximum of ${Notification.maxActions || 0} action button(s). Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`,
8080
data: {
81-
url: 'https://google.com'
81+
url: 'https://google.com',
8282
},
8383
image: '../media/manifest/screenshot-4.png',
8484
icon: '../media/manifest/icon-192x192.png',
@@ -88,11 +88,35 @@
8888
{
8989
action: 'reply',
9090
type: 'text',
91-
title: 'Reply title',
91+
title: 'One (Reply)',
9292
icon: '../media/manifest/icon-192x192.png',
93-
placeholder: 'Reply placeholder'
94-
}
95-
]
93+
placeholder: 'Reply placeholder',
94+
},
95+
{
96+
action: 'two',
97+
type: 'button',
98+
title: 'Two',
99+
icon: '../media/manifest/icon-192x192.png',
100+
},
101+
{
102+
action: 'three',
103+
type: 'button',
104+
title: 'Three',
105+
icon: '../media/manifest/icon-192x192.png',
106+
},
107+
{
108+
action: 'four',
109+
type: 'button',
110+
title: 'Four',
111+
icon: '../media/manifest/icon-192x192.png',
112+
},
113+
{
114+
action: 'five',
115+
type: 'button',
116+
title: 'Five',
117+
icon: '../media/manifest/icon-192x192.png',
118+
},
119+
],
96120
};
97121

98122
const showNotification = () => serviceWorkerRegistration.showNotification(title, options);

0 commit comments

Comments
 (0)