服务工作者获取事件监听器:它捕获了什么?

时间:2017-05-15 08:30:36

标签: javascript web-applications service-worker

我遇到了从服务工作者处捕获抓取事件的问题。

https://localhost/subdir/page.php的页面中,我向服务人员注册:

navigator.serviceWorker.register('https://localhost/subdir/sw.js', {scope: './'}).then( ... );

然后我用以下内容注册Fetch事件监听器:

this.addEventListener('fetch', function(event) { ... });

https://localhost/subdir/page.php的同一页面中,我有四种不同的链接:

<a href="https://localhost/subdir/page2.php">link1</a><br />
<a href="http://localhost/subdir/page2.php">link2</a><br />
<a href="https://otherhost">link3</a><br />
<a href="http://otherhost">link4</a><br />

我注意到服务工作者只从link1捕获了fetch事件,而其他三个事件没有被注意到。

我所做的每一项测试似乎都表明,服务工作者只会收到有关其来源请求的通知。 谁能证实这一点? 任何已知的解决方法?

提前致谢

1 个答案:

答案 0 :(得分:1)

是的,它应该如何用于导航。您不应该拦截进入其他站点的用户。 (您可以访问文档的所有子资源请求,无论其来源如何。)

相关问题