Open ray73864 opened 3 months ago
Hmm, interesting. Apologies for the inconvenience. I assumed the jsdelivr method would work provided it works via NPM, which it does.
If anyone has any suggestions the help would be most appreciated.
I'm writing a browser extension and trying out Keystrokes. Browser extensions have all kind of restrictions. I can't load external scripts from a CDN, scripts must be local. I can't use modules. So I ran into a similar problem.
I've fixed it in an ugly way:
I downloaded the raw https://unpkg.com/browse/@rwh/keystrokes@1.5.6/dist/keystrokes.js file and put it in my project directory, so it's available locally.
The browser extension chokes on the export
at the end of the file:
export {
S as HandlerState,
_ as KeyComboState,
P as Keystrokes,
N as bindKey,
G as bindKeyCombo,
...
so I commented the whole export
out, and replaced it with:
const HandlerState = S;
const KeyComboState = _;
const Keystrokes = P;
const bindKey = N;
const bindKeyCombo = G;
...
Ugly, but it works 😁
When trying to import into the browser by doing
<script src="https://unpkg.com/browse/@rwh/keystrokes@latest/dist/keystrokes.umd.cjs">
I get a 302 redirect and then a 0B file.If I use the version on jsDelivr via
<script src="https://cdn.jsdelivr.net/npm/@rwh/keystrokes@1.5.6/dist/keystrokes.min.js"></script>
I get aSyntaxError: Unexpected token 'export' (at keystrokes.min.js:7:11663)
If I use the non-minified version on jsDelivr via
<script src="https://cdn.jsdelivr.net/npm/@rwh/keystrokes@1.5.6/dist/keystrokes.js"></script>
I get the errorSyntaxError: Unexpected token 'export' (at keystrokes.js:486:1)
I would love to use this library as it looks nicer to use than Hotkeys which requires me to setscopes, etc... But so far I've had zero luck getting it to load in the browser.