Ответ Service Worker FechtEvent.respondWith имеет значение null в iOS 12.1 Safari.IOS

Программируем под IOS
Ответить
Anonymous
 Ответ Service Worker FechtEvent.respondWith имеет значение null в iOS 12.1 Safari.

Сообщение Anonymous »

Я могу загрузить веб-сайт с помощью службы Worker на Android Chrome, macOS Chrome, а также Safari и Windows Chrome для использования в автономном режиме. Когда я пытаюсь загрузить веб-сайт в iOS 12.1 Safari, он работает первым. Но когда я закрываю Safari, выхожу в автономный режим и снова открываю Safari, я получаю следующее сообщение об ошибке:

Safari не может открыть сайт.
Ошибка: «FetchEvent.respondWith получил ошибку: TypeError:
Кажется, нет подключения к Интернету».
==== И в консоли ====
FetchEvent.respondWith получил ошибку: возвращенный ответ имеет значение null

Ниже вы можете увидеть сценарии в текстовой форме. К сожалению, почти ничего не могу сообщить о проблеме, так как не разбираюсь в ней и надеюсь на знающих людей :)
index.html




Title


Offline App


if('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js').then(function (registration) {
console.log('Service Worker Registered');
});
}



sw.js
/*
Copyright 2014 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

importScripts('cache-polyfill.js');

var CACHE_VERSION = 1;
var CURRENT_CACHES = {
prefetch: 'prefetch-cache-v' + CACHE_VERSION
};

self.addEventListener('install', function(event) {
var now = Date.now();

var urlsToPrefetch = [
'/pwa/index.html'
];

console.log('Handling install event. Resources to prefetch:', urlsToPrefetch);

event.waitUntil(
caches.open(CURRENT_CACHES.prefetch).then(function(cache) {
var cachePromises = urlsToPrefetch.map(function(urlToPrefetch) {
var url = new URL(urlToPrefetch, location.href);
url.search += (url.search ? '&' : '?') + 'cache-bust=' + now;

var request = new Request(url, {mode: 'no-cors'});
return fetch(request).then(function(response) {
if (response.status >= 400) {
throw new Error('request for ' + urlToPrefetch +
' failed with status ' + response.statusText);
}

return cache.put(urlToPrefetch, response);
}).catch(function(error) {
console.error('Not caching ' + urlToPrefetch + ' due to ' + error);
});
});

return Promise.all(cachePromises).then(function() {
console.log('Pre-fetching complete.');
});
}).catch(function(error) {
console.error('Pre-fetching failed:', error);
})
);
});

self.addEventListener('activate', function(event) {
var expectedCacheNames = Object.keys(CURRENT_CACHES).map(function(key) {
return CURRENT_CACHES[key];
});

event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.map(function(cacheName) {
if (expectedCacheNames.indexOf(cacheName) === -1) {
console.log('Deleting out of date cache:', cacheName);
return caches.delete(cacheName);
}
})
);
})
);
});

self.addEventListener('fetch', function(event) {
if (!navigator.onLine) {

event.respondWith(
caches.match(event.request).then(function (response) {
if (response) {

return response;
}

console.log('No response found in cache. About to fetch from network...');

return fetch(event.request).then(function (response) {
console.log('Response from network is:', response);

return response;
}).catch(function (error) {
console.error('Fetching failed:', error);
throw error;
});
})
);
}
});


Подробнее здесь: https://stackoverflow.com/questions/534 ... 2-1-safari
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»