Fix notification permission request for Safari
This commit is contained in:
parent
d66bc9c900
commit
c526f1bf3b
@ -335,9 +335,21 @@ function main() {
|
|||||||
function start() {
|
function start() {
|
||||||
|
|
||||||
// Request permission to show notifications
|
// Request permission to show notifications
|
||||||
Notification.requestPermission().then(function(result) {
|
try {
|
||||||
console.log('Notification permission: ' + result);
|
Notification.requestPermission().then(function(result) {
|
||||||
});
|
console.log('Notification permission: ' + result);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// Safari doesn't return a promise for requestPermissions and it throws a TypeError.
|
||||||
|
// It takes a callback as the first argument instead.
|
||||||
|
if (error instanceof TypeError) {
|
||||||
|
Notification.requestPermission(() => {
|
||||||
|
console.log('Notification permission: ' + Notification.permission);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Load initial data
|
// Load initial data
|
||||||
doHttpGet('/games', function(games) {
|
doHttpGet('/games', function(games) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user