Fix notification permission request for Safari
This commit is contained in:
parent
d66bc9c900
commit
c526f1bf3b
@ -335,9 +335,21 @@ function main() {
|
||||
function start() {
|
||||
|
||||
// Request permission to show notifications
|
||||
Notification.requestPermission().then(function(result) {
|
||||
console.log('Notification permission: ' + result);
|
||||
});
|
||||
try {
|
||||
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
|
||||
doHttpGet('/games', function(games) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user