这只是一个愚蠢而简单的问题。我只需要进一步的响应数据......但那是未定义的..
未捕获的ReferenceError:未定义url
self.addEventListener('push', function(event) {
console.log('Push message', event);
// perform action
fetch('slack-url')
.then(
function(response) {
if (response.status !== 200) {
console.log(response.status);
return;
}
// Examine the text in the response
response.json().then(function(data) {
console.log(data);
var url = data;
});
}
)
.catch(function(err) {
console.log('Fetch Error :-S', err);
});
var title = 'Push message';
var stack_url = url;
event.waitUntil(
self.registration.showNotification(title, {
stack_url:stack_url
})
);
});
答案 0 :(得分:0)
self.addEventListener('push', function(event) {
console.log('Push message', event);
var url = "";
// perform action
fetch('slack-url')
.then(
function(response) {
if (response.status !== 200) {
console.log(response.status);
return;
}
// Examine the text in the response
response.json().then(function(data) {
console.log(data);
url = data;
});
}
)
.catch(function(err) {
console.log('Fetch Error :-S', err);
});
var title = 'Push message';
var stack_url = url;
event.waitUntil(
self.registration.showNotification(title, {
stack_url:stack_url
})
);
});