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

fix: allow bundle to be used in web workers #408

Merged
merged 5 commits into from
Oct 26, 2020
Merged

Conversation

alanshaw
Copy link
Member

globalObject is "window" by default which is not available in web workers. Using "self" allows the bundle to work in both environments.

resolves ipfs/js-ipfs#2349

cc @Gozala

`globalObject` is `"window"` by default which is not available in web workers. Using `"self"` allows the bundle to work in both environments.
@alanshaw alanshaw requested a review from hugomrdias August 14, 2019 13:04
Copy link
Member

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alanshaw mind adding a test for this? I remember this problem existing in the past and there being a great endeavour to remove window references from everywhere in the code

@alanshaw
Copy link
Member Author

alanshaw commented Sep 6, 2019

I don't have the bandwidth to add this test atm - @hugomrdias any chance you can pull this over the line?

@hugomrdias hugomrdias self-assigned this Sep 9, 2019
@ay2306
Copy link

ay2306 commented Nov 28, 2019

@alanshaw Can I work on the test for this pull request?

@alanshaw
Copy link
Member Author

@ay2306 🙏 yes please that would be amazing!

@ay2306
Copy link

ay2306 commented Dec 2, 2019

@alanshaw To test this PR/commit, can I add a job in Travis to clone js-ipfs, build it using aegir and then run a headless browser to test if is there is no error in web worker?

@@ -21,9 +21,6 @@ const env = {
// Webpack overrides for karma
const karmaWebpackConfig = merge.strategy({ plugins: 'replace' })(webpackConfig(), {
entry: '',
output: {
libraryTarget: 'var'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this is/was necessary, but the added test passes with globalObject as 'self' or 'window' unless this is removed, in which case it passes with globalObject as 'self' and fails with it as 'window' as reported in ipfs/js-ipfs#2349.

The js-IPFS tests pass without this block when run in the browser/webworkers so I'm not sure if it's necessary - ipfs/js-ipfs#3343

@achingbrain achingbrain merged commit 3f72e50 into master Oct 26, 2020
@achingbrain achingbrain deleted the fix/global-object branch October 26, 2020 14:38
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.

Loading ipfs-js bundle in worker fails with ReferenceError: window is not defined
5 participants