https://browserid.org/include.js 在 Chrome 中失败,并显示 html5 appcache 清单
如何在 Chrome 中从 appcached web 应用程序使用 browserid.org?此代码:
<html manifest="test.appcache"><head>
<script src="https://browserid.org/include.js"></script>
<script>
function test() {
if(navigator.id){
alert('OK!');
} else {
alert('Oops!');
}
}
</script>
</head><body onload="test();">test</body></html>
与 test.appcache:
CACHE MANIFEST
和 .htaccess: 结合使用,
AddType text/cache-manifest .appcache
每次在 Firefox 中刷新时都会发出“确定”警报。在 Chrome 中,它会在您第一次访问它时发出“OK”警报,但每次您下次刷新它时(即从应用程序缓存提供服务时)都会发出“哎呀”警报。
关于它未能包含的文件的一些事实:
- 它是跨源的
- 它通过 https 提供服务
- 它有一个“Cache-Control:public,max-age = 0”响应标头
仍然,我不明白为什么这在 FF 中有效,但是在 Chrome 中失败。我认为这在某种程度上与“HTTP 缓存标头和通过 TLS 提供的缓存页面的限制被清单覆盖”相关。在 http://www.w3.org/TR/html5/offline.html 和/或“通过 SSL,清单中的所有资源都必须遵守同源策略。”在 http://appcachefacts.info/ 上,但我不明白具体如何。
我在 Ubuntu 上使用 Chromium 12.0.742.112 进行了测试。
我想一种解决方法是创建一个不支持 browserid 的可缓存应用程序,并将 browserid 登录按钮放在不在缓存清单中的 iframe 中,并使用 FALLBACK: 显示灰色的 browserid 登录按钮。但我希望也许有人有合适的解决方案。
How can I use browserid.org from an appcached webapp in Chrome? This code:
<html manifest="test.appcache"><head>
<script src="https://browserid.org/include.js"></script>
<script>
function test() {
if(navigator.id){
alert('OK!');
} else {
alert('Oops!');
}
}
</script>
</head><body onload="test();">test</body></html>
combined with test.appcache:
CACHE MANIFEST
and with .htaccess:
AddType text/cache-manifest .appcache
will alert 'OK' every time you refresh it in Firefox. In Chrome, it will alert 'OK' the first time you visit it, but 'Oops' every next time you refresh it (i.e., when served from the appcache).
Some facts about the file it's failing to include:
- it's cross-origin
- it's served over https
- it has a "Cache-Control: public, max-age=0" response header
Still, I don't understand exactly why this works in FF but fails in Chrome. I think this is related in some way to "HTTP cache headers and restrictions on caching pages served over TLS are overridden by manifests." on http://www.w3.org/TR/html5/offline.html and/or "Over SSL, all resources in the manifest must respect the same-origin policy." on http://appcachefacts.info/ but I don't understand exactly how.
I tested with Chromium 12.0.742.112 on Ubuntu.
I guess one work-around would be to create a cacheable app without browserid support, and put the browserid login button in an iframe that's not in the caching manifest, with a FALLBACK: that displays a greyed-out browserid login button. but i was hoping maybe someone has a proper solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我做了一些实验,这只影响通过 http 提供服务的 Web 应用程序。因此,为了避免这种情况,只需通过 https 提供您的 Web 应用程序即可。
我认为这仍然是 Chrome 中的一个错误,但至少这是一个解决方法,因此将问题标记为已回答。
I experimented a bit, and this only affects web apps that are served over http. So to avoid it, simply serve your web app over https.
it is still a bug in Chrome i think, but at least this is a workaround for it, so marking question as answered.