Does not work in web worker #5

Open
opened 2020-06-12 08:17:58 +00:00 by Ghost · 5 comments

error message:

Uncaught ReferenceError: window is not defined
browser-atob.js:44
error message: ``` Uncaught ReferenceError: window is not defined browser-atob.js:44 ```
Owner

Can you propose a solution?

Is atob defined on... self or whatever it is that workers have?

Does globalThis work?

Can you propose a solution? Is `atob` defined on... `self` or whatever it is that workers have? Does `globalThis` work?
Author
module.exports = function _atob(str) {
  return atob(str)
}

just with the function name works for me (both browser and web work)

reference:
https://caniuse.com/#search=atob

https://github.com/hughsk/atob-lite/blob/master/atob-browser.js

``` module.exports = function _atob(str) { return atob(str) } ``` just with the function name works for me (both browser and web work) reference: https://caniuse.com/#search=atob https://github.com/hughsk/atob-lite/blob/master/atob-browser.js
Owner

How about just put var window = self; in your WebWorker script?

So many things depend on this and it is so abused by things like webpack and browserify, etc, etc that I don't want to rock the boat.

How about just put `var window = self;` in your WebWorker script? So many things depend on this and it is so abused by things like webpack and browserify, etc, etc that I don't want to rock the boat.
Owner

I could release a version 3 that uses something like:

'undefined' !== typeof window ? window : 'undefined' !== typeof self ? self : golablThis
I could release a version 3 that uses something like: ```js 'undefined' !== typeof window ? window : 'undefined' !== typeof self ? self : golablThis ```
Author

That seems make sense. Thanks!

That seems make sense. Thanks!
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: coolaj86/atob.js#5
No description provided.