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

Add WebWorker support for LiteBuffer #221

Open
ygrill-astek opened this issue Apr 5, 2022 · 0 comments
Open

Add WebWorker support for LiteBuffer #221

ygrill-astek opened this issue Apr 5, 2022 · 0 comments

Comments

@ygrill-astek
Copy link

LiteBuffer isn't supported in WebWorker context as the code use window object which is undefined in WebWorker

Solution which seems to work for me
Use following code in LiteBuffer.js

if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
  Object.defineProperty(WorkerGlobalScope, 'Buffer', {
    configurable: true,
    enumerable: false,
    value: Buffer,
    writable: true,
  });
} else {
  Object.defineProperty(window, 'Buffer', {
    configurable: true,
    enumerable: false,
    value: Buffer,
    writable: true,
  });

}

instead of only

Object.defineProperty(window, 'Buffer', {
     configurable: true,
     enumerable: false,
     value: Buffer,
     writable: true,
   });
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

No branches or pull requests

1 participant