-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
'Web workers' do not work in editor #3414
Comments
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already. |
Seems to work on Chrome. Tried on Firefox, but failed with
So user files are being served with a default I can work on a fix for this. |
This is the correct code
I have made a few changes in this code
These changes ensure the rectangle stays fixed at the specified position (50,50) with dimensions 100×80, while still allowing communication with the worker. |
#3414Web workers work fine in all browsersThe problem was only in the code, and I have fixed the issues in the code. Bugs have been fixed too. 🪲 |
I think you misunderstood my problem. The code I posted worked fine in VSC on my desktop but not in the in the p5js web editor. @dipamsen discovered that the problem appears to be with the mime type and is browser specific. I tried the web editor in Chrome and confirmed that the sketch worked as expected. So there was nothing wrong with my code and it was in fact correct. The changes you made were superficial and did not change the program logic. |
I have added the fix in #3416, by which the sketch works properly in firefox: However, I have realised something else while working on this - This only works for a sketch which is saved to someone's account, and thus has a sketchId. If a non-logged in user tries to use this on the default sketch provided on the home page, it doesn't work, since it does not have any sort of url like I am unsure what the general solution for this issue is - somehow replace file path strings with Blob URLs? cc @raclim |
That's great you have identified the problem created a fix and potentially uncovered a larger issue. Nice work! |
Really cool investigation work, everyone! Jumping in to share a couple of resources here related to answering style @Sanjai-Shaarugesh: in the future, please be a little more mindful of answer tone. In this case, there is an issue worth discussing here, and it's always best to take the time to really understand the problem before jumping in with a fix. Additionally, please consult the PF guidelines on answering questions on Discourse which is also good to have in mind in GitHub spaces! |
Thanks for raising and looking into this issue!
This is a great catch! I'm not entirely sure yet what might be the best solution for it either yet, but I feel like Blob URLs make sense to me so far as a simpler fix and could be worth a shot! We do have an area where we're creating them within the editor for the Preview. Since this seems like it might be something beyond web workers, we can merge your PR and create a new issue dedicated to this if that sounds good? |
@raclim makes sense! |
Awesome! I just merged this in, the next set of changes should be out by sometime next week! |
p5.js version
1.11.1
What is your operating system?
Mac OS
Web browser and version
Firefox 136.0.2 (64bit) & Safar 18.3.1i
Actual Behavior
Although it is possible to create a web worker object, posting and receiving messages from it does not appear to work.
I have created a simple sketch in the editor to demonstrate the problem.
Expected Behavior
The sketch should display a randomly display a rectangle every 2 seconds, it uses a web worker to calculate the position and size and send the information back to the main sketch. This works as expected using VSC but fails in the web editor.
Steps to reproduce
Steps:
I have included the code below but it is easier to see it in action in the editor here.
Snippet:
main.js
worker.js
The text was updated successfully, but these errors were encountered: