-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
print("content") outside of setup/draw invokes print dialog. possible to catch with FES? #4272
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. |
Hm odd! I am not able to recreate on Mac 10.15.2 using the online editor and Firefox 72.0.2. This sketch just prints the text in the console for me:
|
Ah, I'm realizing my mistake. I tried to use the I realize my case is probably a bit unusual, but it might be worth updating the documentation? |
I don't think this is something we can specifically document just for |
@limzykenneth Can I work on this issue? |
@debajitdeb11 Sure, do have a look at it. I'm not sure how would the FES detect |
The source code for the web editor is located in another repo but why do you need the source code for it for this issue? |
i think this is a great place for FES. if someone is interested in working on it i’m also happy to answer questions, code review, whatever! |
@debajitdeb11 if you are still working on this maybe |
@akshay-99 the thing with calling print(...args) outside setup or draw is that it gets called before the library is loaded and browser calls window.print() . So I think it's hard for FES to detect it.
@outofambit what do you suggest about this? |
@DivyamAhuja I am sorry I didn't reply earlier. I must have missed this comment somehow. Also you are right that the call is made before the library initialises. And hence my mention of window.onbeforeprint = () => {
helpForMisusedAtTopLevelCode(new ErrorEvent('print', {message:'print used'}));
} The effect of this now is that if a |
It is interesting to note that there is another way to handle this, one that is not just limited to We can simply redefine the function in the let somethingBackup = window.something;
window.something = (params) => {
helpForMisusedAtTopLevelCode(new ErrorEvent('something', {message:'something used'}));
somethingBackup(params);
} |
@debajitdeb11 @DivyamAhuja is anyone working on this? |
@akshay-99 No, am not working on it. You can continue working on it if you want. |
BTW calling print(); with no parameters invokes the browsers print dialog. Having a command to override the system print would be great, NoPrintDialog(); Could the sandbox flags be used to disable the window.print()? Or could we just hijack window.print() https://stackoverflow.com/questions/32181838/override-window-print-for-all-windows-using-window-prototype |
I think overriding default print function with this should work.
current implementation adds print function to p5 class while overriding window.print will be helpful I think. |
@DivyamAhuja ah that's interesting. I was talking about overriding it for catching its use for outside setup and draw to warn the user. But your idea of removing p5.prototype.print and overriding window directly is simpler. One question I have in mind is instance mode, as this would leak p5's functionality to the global object even in instance mode. So hypothetically if the user is also using some other script that also overrides print, and using p5 in instance mode to avoid any clashes, this print functionality would still clash. Which means it would depend on the order of the import which script's print is used. But this is a very unlikely situation indeed. @hellonearthis yeah I guess a command or a parameter which when called or set true, would map print to console.log even when called with 0 parameters would help in that case. |
@akshay-99 Yeah, I didn't think of a case with multiple libraries. In this case overriding may really be flawed |
I have had this print() problem when used inside a draw() loop. p5 could treat print() as console.log('') to would prevent the browser print() to not popup Overriding outside of the p5 scope is problematic unless it could be address like p5.print('hi'); |
This simple sketch is very easy for a novice user write. I recommend print with no args call console.log.
|
Thank you all for working on this. I'd like to bump up this issue for the upcoming 1.7.0 release with another print() related issue #2765. |
With the suggested For the more general case for |
Most appropriate sub-area of p5.js?
Details about the bug:
The following code causes the print dialog to appear in Firefox (using editor.p5js.org).
The text was updated successfully, but these errors were encountered: