Chrome extension: Serviceworker cross origin failing

送分小仙女□ 提交于 2019-12-12 06:51:47

问题


Docs claim that:

By adding hosts or host match patterns (or both) to the permissions section of the manifest file, the extension can request access to remote servers outside of its origin

My ≪manifest.json≫:

{"manifest_version":2,"name":"","version":"0","permissions":["http://example.org/"],"background":{"scripts":["asd"]}}

≪asd≫:

navigator.serviceWorker.register('sdf.js',{scope:'http://example.org/'}).then(x=>console.log('done', x))

≪sdf.js≫:

addEventListener('fetch', e=> e.respondWith(new Response('url: '+e.request.url,{headers:{'content-type':'text/html'/*, etc*/}})))

I loaded the code using ≪Load unpacked extension≫; It crashed without any error message:

Apparently the code "permissions":["http://example.org/"] crashed the extension.

How to set permissions for Chrome Extension cross-origin serviceworker? Is there a required Chrome flag?


回答1:


As various folks have pointed out in the comments, it's not possible for a service worker to control a Chrome Extension, and it's not possible to register a service worker scoped to an https: origin within the context of a Chrome Extension.



来源:https://stackoverflow.com/questions/46760820/chrome-extension-serviceworker-cross-origin-failing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!