-
Notifications
You must be signed in to change notification settings - Fork 320
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
window is undefined when trying to run in worker file on browser #658
Comments
Thanks for the report! You are right that The following code could be a replacement without depending on
Could you try it out and open a PR if it works? |
Tested your code and it works fine with worker. The Here is my PR #660 |
May I know the status of this? Anything that I need to do on my side? |
I didn't have the time yet to try it out but I plan on doing so in the next few days |
I would also love to get this merged if it would solve this issue. If any additional help is required, I'm happy to lend a hand. |
I added a few more commits to your PR and merged it. Can you please test the latest main branch from GitHub and let me know if it works? If so, I can release a new version. |
Tested the main branch locally and works fine using with worker |
Thanks for the confirmation! I just published v4.0.1, which includes this patch. |
Describe the bug
The bug is regarding the
window
global object that is available when running in browser. However, when trying to run the upload process in a worker thread on client side, the window object is not defined in the worker global scope.In the file /lib/browser/index.js, line 31 - 33, the code uses the window global object to check for
XMLHttpRequest
andBlob
to determine theisSupported
property.Running this in worker will return
window is not defined
since the code assume thatwindow
is available. I understand the thoughts here since its supposed to be running in browser. I supposed we should put a check instead of assuming thatwindow
is available.To Reproduce
new Worker()
window not defined
error in browser logs. You can copy the upload code part from/demos/browser/demo.js
Expected behavior
The upload should work on both the main thread and worker thread on browser. I supposed we should not be assuming that window would always be defined or something..
Just to add,
![image](https://private-user-images.githubusercontent.com/132123505/289383547-7081c337-915c-4f9a-9a7f-8059286db7c3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MTUzNzAsIm5iZiI6MTczOTYxNTA3MCwicGF0aCI6Ii8xMzIxMjM1MDUvMjg5MzgzNTQ3LTcwODFjMzM3LTkxNWMtNGY5YS05YTdmLTgwNTkyODZkYjdjMy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNVQxMDI0MzBaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mYTI5ZTYzMDk3ODJmOWViNzc5OGQxYWNmMGY5MDgxNTk1NDFkMzc2Y2VkNTRkYjVlMjNmOGE1ZDhjMTNiYmU1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.AHRnn88tO32YsfZ6wePhL80xhlDLWUmC25Z6SdW1URc)
I have it working locally where I modified the file
/lib/browser/index.js
like so,Built the code and it works fine. The upload works on both the main thread and worker thread.
However, this might not be the best fix.
The text was updated successfully, but these errors were encountered: