Skip to content

Conversation

@sdass1918
Copy link

Resolves processing/p5.js-web-editor#3678

Changes:

  • Updated src/core/environment.js
  • Modified p5.prototype.print to check for empty arguments before calling window.print().
  • Added a console warning when print() is called without any arguments instead of triggering the browser print dialog.

Behavior Before:

print(); // opened browser print popup
print("Hello"); // logged correctly

Behavior After:

print(); // logs a warning, no popup
print("Hello"); // logs correctly

PR Checklist

@welcome
Copy link

welcome bot commented Nov 8, 2025

🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors!
🤔 Please ensure that your PR links to an issue, which has been approved for work by a maintainer; otherwise, there might already be someone working on it, or still ongoing discussion about implementation. You are welcome to join the discussion in an Issue if you're not sure!
🌸 Once your PR is merged, be sure to add yourself to the list of contributors on the readme page !

Thank You!

windowPrintDisabled = true;
}
}
console.warn('p5.js: print() called with no arguments. Nothing to print.');

Choose a reason for hiding this comment

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

shouldn't we print a newline character if no argument is passed.
It is a convention that is followed in java println or js console.log.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, @oneplusiota! 🙏

That’s a great point — following the convention of console.log() and Java’s println makes sense for consistency.

I can update the implementation so that when print() is called without any arguments, it simply prints a newline (i.e., console.log("")) instead of showing a warning.

Would you prefer that behaviour instead of the warning message? I can make the adjustment and push an update once confirmed.

Choose a reason for hiding this comment

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

yeah this will work.

Copy link
Author

Choose a reason for hiding this comment

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

Great! I've updated the implementation so that print() with no arguments now outputs a blank line (console.log("")).
Let me know if any further tweaks are needed. 👍

@sdass1918 sdass1918 requested a review from oneplusiota November 9, 2025 06:38
Copy link
Collaborator

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

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

From my opinion, if we write just print() , it's supposed to print() the window. I don't find that to be a bug? Probably we could improve the documentations letting the user know what does print() does with no arguments? What you think?

@oneplusiota
Copy link

@perminder-17 I disagree. Why should print work differently for different arguments. It's work is to write to the output stream. And more importantly, there is no use of the print window functionality in the p5 editor. And in case the user does want to print the page, they can do so by directly using the browser's print screen functionality.

@sdass1918
Copy link
Author

Thanks both for your feedback — I appreciate the different perspectives here 🙏

My intent with this fix was to prevent print() with no arguments from unintentionally triggering the browser’s print dialog, since that can interrupt the sketch execution and isn’t consistent with how print() behaves elsewhere in p5.js or in typical console output functions.

I agree that consistency is important. From a usability point of view, having print() behave like console.log("") (i.e., output a blank line) seems clearer and safer than opening the print window, especially since users can explicitly call window.print() if they want that behavior.

Copy link

@oneplusiota oneplusiota left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Collaborator

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

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

I'm so sorry, but this is the intended behavior of the print() functions and these are the discussions related to it: #4272 and #2765.

Thanks for all your work on this. Keep looking at the issue section: https://github.com/processing/p5.js/issues and would be very great to ask maintainers confirmation on the issues before working.

Really thanks for your work and patience on this one.

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.

print function opens up print webpage popup

3 participants