File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
packages/workbox/templates Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 1- export default async function ( ctx , inject ) {
1+ function onError ( error ) { < % if ( options . dev ) { % > console . error ( 'Error registering workbox:' , error ) < % } % > }
2+
3+ export default function ( ctx , inject ) {
24 let workbox = { }
35
46 try {
7+ // workbox-window does not detects unsupported browsers
58 if ( ! 'serviceWorker' in navigator ) {
6- throw new Error ( 'Serviceworker is not supported!' )
9+ throw new Error ( 'serviceWorker is not supported in current browser !' )
710 }
811
12+ // Use require() instead of import() to prevent creating extra chunk
13+ // Use es5 version to prevent crashing older browsers while parsing bundle
914 const { Workbox } = require ( 'workbox-cdn/workbox/workbox-window.<%= options.dev ? ' dev ' : 'prod' % > . es5 . mjs ')
1015
1116 workbox = new Workbox ( '<%= options.swURL %>' , {
1217 scope : '<%= options.swScope %>'
1318 } )
1419
15- workbox . register ( )
16- } catch ( e ) {
17- console . warn ( 'Cannot register workbox:' , e )
20+ workbox . register ( ) . catch ( onError )
21+ } catch ( error ) {
22+ onError ( error )
1823 }
1924
2025 // Inject as $workbox
You can’t perform that action at this time.
0 commit comments