Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching the result of atob existence is causing web worker to crash #174

Conversation

Itaypa
Copy link

@Itaypa Itaypa commented Feb 21, 2024

Hi,

Awesome library, I use it in all my projects.

recently I used this library in a web app that launches a web worker, the issue occurred when _hasatob is calculated when app is loaded on the main thread (while atob) exists and when running the web worker it mistakenly fails because it does not exist.

by not caching the result it solves the issue

@dankogai dankogai merged commit c19b960 into dankogai:main Feb 21, 2024
4 checks passed
@dankogai
Copy link
Owner

Thank you!

I was a little puzzled with:

--- a/base64.js
+++ b/base64.js
@@ -42,8 +42,8 @@
      * @deprecated use lowercase `version`.
      */
     var VERSION = version;
-    var _hasatob = typeof atob === 'function';
-    var _hasbtoa = typeof btoa === 'function';
+    var typeof atob === 'function' = typeof atob === 'function';
+    var typeof btoa === 'function' = typeof btoa === 'function';
     var _hasBuffer = typeof Buffer === 'function';
     var _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined

But It was gone after npm test which rebuilds *.js and *.mjs from *.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants