PWA在POST上打开Safari。有没有办法做到这一点?

时间:2019-01-17 20:36:54

标签: mobile-safari service-worker progressive-web-apps

我正在将现有的应用程序转换为PWA。该PWA的一部分处理来自登录表单的POST,并重定向到另一个页面。在Safari中,如果您从主屏幕打开该应用并尝试登录,它将在Safari中打开一个新标签。我希望这不会发生。

我尝试过在POST上返回并缓存重定向的页面。它似乎工作了一段时间,但随后又恢复了旧的方式。我已经调试了代码,并且一旦从提取中获得响应,它似乎就会切换。这是我的提取处理程序

  if ((e.request.cache === 'only-if-cached' && e.request.mode !== 'same-origin') || (e.request.type === "POST") {
    return;
}

e.respondWith(
    caches.match(e.request)
        .then(function (response) {
            //Cache Hit

            // IMPORTANT: Clone the request. A request is a stream and
            // can only be consumed once. Since we are consuming this
            // once by cache and once by the browser for fetch, we need
            // to clone the response.
            var fetchRequest = e.request.clone();

            return fetch(fetchRequest).then(
                function (response) {
                    //Check to see if we are valid
                    if (!response || response.status !== 200 || response.type !== 'basic') {
                        return response;
                    }
                    // IMPORTANT: Clone the response. A response is a stream
                    // and because we want the browser to consume the response
                    // as well as the cache consuming the response, we need
                    // to clone it so we have two streams.

                    var responseToCache = response.clone();

                    caches.open(CACHE_NAME)
                        .then(function (cache) {
                            cache.put(e.request, responseToCache);
                        });
                    return response;
                })
        }))

我希望Safari不会打开,但是会打开,我完全不知道如何解决此问题。

0 个答案:

没有答案