Noções básicas sobre o escopo do Service Worker
Estou tentando implementar umService Worker
em uma página de teste. Meu objetivo final é um aplicativo que opera offline. A estrutura da pasta está abaixo
/myApp
...
/static
/mod
/practice
service-worker.js
worker-directives.js
foopage.js
/templates
/practice
foopage.html
Estou registrando um técnico de serviço, como mostrado abaixo (dentro deservice-worker.js
):
navigator.serviceWorker.register('../static/mod/practice/service-worker.js').then,(function(reg) {
console.log('Registration succeeded. Scope is ' + reg.scope);
...
}
e no console eu vejo
Registration succeeded. Scope is https://example.com/static/mod/practice/
Se minha página estiver localizada emhttps://example.com/practice/foopage
, preciso ter certeza de que meuservice worker
escopo éhttps://example.com/practice/foopage
?
Se eu tentar definir o escopo noregister
chamada de função como
navigator.serviceWorker.register('../static/mod/practice/service-worker.js', { scope: '/practice/foopage/' }).then(function(reg) {
...
}
Eu recebo o erro
Registration failed with SecurityError: Failed to register a ServiceWorker: The path of the provided scope ('/practice/foopage/') is not under the max scope allowed ('/static/mod/practice/'). Adjust the scope, move the Service Worker script, or use the Service-Worker-Allowed HTTP header to allow the scope.
Questão é: O que exatamente fazescopo referir-se? É a coleção de URLs que oservice worker
acabará por controlar? Preciso me moverservice-workers.js
Em outro lugar? Se sim, onde?