From 8cb117e0f5008dc491b4bef7db762bc23f777c2b Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Wed, 5 Jul 2023 07:15:43 -0400 Subject: [PATCH] Ask to disable printing when print() called with no arguments --- src/core/environment.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core/environment.js b/src/core/environment.js index 16971c0b79..34442423b3 100644 --- a/src/core/environment.js +++ b/src/core/environment.js @@ -16,6 +16,7 @@ p5.prototype._lastFrameTime = window.performance.now(); p5.prototype._targetFrameRate = 60; const _windowPrint = window.print; +let windowPrintDisabled = false; /** * The print() function writes to the console area of @@ -43,7 +44,16 @@ const _windowPrint = window.print; */ p5.prototype.print = function(...args) { if (!args.length) { - _windowPrint(); + if (!windowPrintDisabled) { + _windowPrint(); + if ( + window.confirm( + 'You just tried to print the webpage. Do you want to prevent this from running again?' + ) + ) { + windowPrintDisabled = true; + } + } } else { console.log(...args); }