{"action":"created","issue":{"url":"https://api.github.com/repos/GoogleChrome/workbox/issues/1504","repository_url":"https://api.github.com/repos/GoogleChrome/workbox","labels_url":"https://api.github.com/repos/GoogleChrome/workbox/issues/1504/labels{/name}","comments_url":"https://api.github.com/repos/GoogleChrome/workbox/issues/1504/comments","events_url":"https://api.github.com/repos/GoogleChrome/workbox/issues/1504/events","html_url":"https://github.com/GoogleChrome/workbox/issues/1504","id":327821835,"node_id":"MDU6SXNzdWUzMjc4MjE4MzU=","number":1504,"title":"Workbox 3 module loading may depend on non-spec-compliant 'importScripts(...)' behavior (in some cases)","user":{"login":"josephliccini","id":7726025,"node_id":"MDQ6VXNlcjc3MjYwMjU=","avatar_url":"https://avatars3.githubusercontent.com/u/7726025?v=4","gravatar_id":"","url":"https://api.github.com/users/josephliccini","html_url":"https://github.com/josephliccini","followers_url":"https://api.github.com/users/josephliccini/followers","following_url":"https://api.github.com/users/josephliccini/following{/other_user}","gists_url":"https://api.github.com/users/josephliccini/gists{/gist_id}","starred_url":"https://api.github.com/users/josephliccini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josephliccini/subscriptions","organizations_url":"https://api.github.com/users/josephliccini/orgs","repos_url":"https://api.github.com/users/josephliccini/repos","events_url":"https://api.github.com/users/josephliccini/events{/privacy}","received_events_url":"https://api.github.com/users/josephliccini/received_events","type":"User","site_admin":false},"labels":[{"id":832843601,"node_id":"MDU6TGFiZWw4MzI4NDM2MDE=","url":"https://api.github.com/repos/GoogleChrome/workbox/labels/browser-compat","name":"browser-compat","color":"7af76c","default":false},{"id":525171896,"node_id":"MDU6TGFiZWw1MjUxNzE4OTY=","url":"https://api.github.com/repos/GoogleChrome/workbox/labels/docs","name":"docs","color":"bfdadc","default":false},{"id":721429162,"node_id":"MDU6TGFiZWw3MjE0MjkxNjI=","url":"https://api.github.com/repos/GoogleChrome/workbox/labels/workbox-sw","name":"workbox-sw","color":"6377e8","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-05-30T17:12:37Z","updated_at":"2018-05-31T19:46:21Z","closed_at":null,"author_association":"NONE","body":"**Library Affected**:\r\nworkbox-sw 3.X\r\n\r\n**Browser & Platform**:\r\nEffect is really only present on MS Edge\r\n\r\n**Issue or Feature Request Description**:\r\nAccording to the SW Spec:\r\n![image](https://user-images.githubusercontent.com/7726025/40735732-c95070f0-63f0-11e8-83b7-c5b55d299fab.png)\r\n\r\nHowever, there are cases where workbox (via its `Proxy`) may run `importScripts(...)` during runtime.\r\n\r\nHere's an example:\r\n```ts\r\nimportScripts('/workbox-v3.2.0/workbox-sw.js');\r\n\r\nworkbox.precaching.precacheAndRoute([{ // <-- `workbox.precaching` implicitly calls `importScripts(...)` via ES6 Proxy.  As long as this happens during 'install', there's no issues\r\n    file: '/app.js',\r\n    revision: 'abc123'\r\n}]);\r\n\r\nself.addEventListener('fetch', async event => {\r\n    const strategy = new workbox.strategies.CacheFirst({ /* ... */ }); // <-- This will call `importScripts(...)` via ES6 Proxy.  Since this happens outside of 'install', Edge (according to spec recommendations) will throw `NetworkError`\r\n    const result = await strategy.handle({ event }) || Response.error();\r\n    event.respondWith(Promise.resolve(result));\r\n});\r\n```\r\n\r\nTo be honest it's more of a Chrome / FF bug then a workbox bug, and maybe the spec should be updated and the browsers should align one way or another, _but_ for workbox to work correctly in Edge, a note in the docs or a descriptive console error on this case would be good.\r\n\r\nYou could probably `try-catch` and look for `NetworkError`, and if the worker state is not `'install'`, ask the user to `importScripts(...)` any workbox modules directly during `install` if they won't be imported during install by default.\r\n\r\nSo the workaround is:\r\n```ts\r\nimportScripts('/workbox-v3.2.0/workbox-sw.js');\r\nimportScripts('/workbox-v3.2.0/workbox-precaching.prod.js'); // <-- hit during 'install'\r\nimportScripts('/workbox-v3.2.0/workbox-strategies.prod.js'); // <-- hit during 'install'\r\n\r\nworkbox.precaching.precacheAndRoute([{ // <-- `workbox.precaching` already available, no `importScripts(...)` needed\r\n    file: '/app.js',\r\n    revision: 'abc123'\r\n}]);\r\n\r\nself.addEventListener('fetch', async event => {\r\n    const strategy = new workbox.strategies.CacheFirst({ /* ... */ }); // <-- `workbox.strategies` already available, no `importScripts(...)` needed\r\n    const result = await strategy.handle({ event }) || Response.error();\r\n    event.respondWith(Promise.resolve(result));\r\n});\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/GoogleChrome/workbox/issues/comments/393656444","html_url":"https://github.com/GoogleChrome/workbox/issues/1504#issuecomment-393656444","issue_url":"https://api.github.com/repos/GoogleChrome/workbox/issues/1504","id":393656444,"node_id":"MDEyOklzc3VlQ29tbWVudDM5MzY1NjQ0NA==","user":{"login":"jeffposnick","id":1749548,"node_id":"MDQ6VXNlcjE3NDk1NDg=","avatar_url":"https://avatars1.githubusercontent.com/u/1749548?v=4","gravatar_id":"","url":"https://api.github.com/users/jeffposnick","html_url":"https://github.com/jeffposnick","followers_url":"https://api.github.com/users/jeffposnick/followers","following_url":"https://api.github.com/users/jeffposnick/following{/other_user}","gists_url":"https://api.github.com/users/jeffposnick/gists{/gist_id}","starred_url":"https://api.github.com/users/jeffposnick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeffposnick/subscriptions","organizations_url":"https://api.github.com/users/jeffposnick/orgs","repos_url":"https://api.github.com/users/jeffposnick/repos","events_url":"https://api.github.com/users/jeffposnick/events{/privacy}","received_events_url":"https://api.github.com/users/jeffposnick/received_events","type":"User","site_admin":false},"created_at":"2018-05-31T19:46:21Z","updated_at":"2018-05-31T19:46:21Z","author_association":"COLLABORATOR","body":"CC: @philipwalton who knows more about ESM usage, in case you run into any issues."}}
{"actor":{"display_login":"jeffposnick"}}