cla*_*oda 5 javascript asp.net iis service-worker progressive-web-apps
我有以下网站托管两个 PWA。
www.xy.com/z
Run Code Online (Sandbox Code Playgroud)
我的PWA A托管在
www.xy.com/z/a
Run Code Online (Sandbox Code Playgroud)
和PWA B托管于
www.xy.com/z/b
Run Code Online (Sandbox Code Playgroud)
我从源头为PWA A注册了一个 Service Worker,www.xy.com/z/a如下所示。
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/z/a/sw.js', {scope: '/'}).then(function (registration) {
console.log('Service worker registration succeeded:', registration);
}).catch(function (error) {
console.log('Service worker registration failed:', error);
});
} else {
console.log('Service workers are not supported.');
}
Run Code Online (Sandbox Code Playgroud)
我以同样的方式从源头为PWA B注册一个 Service Workerwww.xy.com/z/b
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/z/b/sw.js', {scope: '/'}).then(function (registration) {
console.log('Service worker registration succeeded:', registration);
}).catch(function (error) {
console.log('Service worker registration failed:', error);
});
} else {
console.log('Service workers are not supported.');
}
Run Code Online (Sandbox Code Playgroud)
至于注册服务工作者并重定向到属性 start_urls,一切似乎都很好。两个 PWA 都会自动提示 A2HS 并安装到设备的应用程序部分。问题是PWA A和B都访问 上的共享内容www.xy.com/z/。当他们的 Service Worker 提供超出范围的内容时,www.xy.com/z/ 我会在 PWA 顶部显示不需要的浏览器 URL。
我希望能够通过将Service-Worker-Allowed添加到我的 web.config 来解决此问题,以指示这些服务工作人员可以提供其范围之外的内容。
<location path="z/a/sw.js">
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Service-Worker-Allowed" value="/" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
<location path="z/b/sw.js">
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Service-Worker-Allowed" value="/" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
Run Code Online (Sandbox Code Playgroud)
我是否应该能够消除使用重定向到超出范围的内容(同一域)时显示的浏览器网址,Service-Worker-Allowed或者我是否误解了这一点?
编辑:
我已经使用 chrome 工具验证Service-Worker-Allowed了它被添加到标头中,尽管我们知道这是因为超出范围的服务工作者突然注册了。
安卓
IOS