Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing Dexie in Service Worker

is it possible to import Dexie in service worker? importScripts("https://unpkg.com/dexie@latest/dist/dexie.js");

resulted in : The script resource is behind a redirect, which is disallowed. I've to import it locally to the worker by saving the code into a local file, but got a "window is undefined error" although the Dexie code seems to check for self instead of window...

Am I missing something? {typeof window !== 'undefined' ? window :global;}

like image 286
Yaniv Peretz Avatar asked Nov 20 '25 15:11

Yaniv Peretz


1 Answers

URLs passed in to importScripts() can't result in HTTP redirections. They must return responses with the correct JavaScript MIME type, and with a ok (2xx) status code.

Requesting https://unpkg.com/dexie@latest/dist/dexie.js results in an HTTP redirection to https://unpkg.com/[email protected]/dist/dexie.js.

You should be able to import Dexie if you use the final, redirected URL:

importScripts('https://unpkg.com/[email protected]/dist/dexie.js');
like image 59
Jeff Posnick Avatar answered Nov 22 '25 23:11

Jeff Posnick