JSFiddle - React, Tailwind, and code Playground

HTML

<p>This is a printable webpage.</p>
<button type="button">Print</button> <span>(may not work on mobile browsers, you'll need to use the browser menu)</span>
<pre></pre>

JavaScript

var output = document.querySelector('pre');

function writeOutput(message) {
	output.textContent += message + "\n";
}

window.addEventListener('beforeprint', function (event) {
	writeOutput("onbeforeprint fired");
});

window.addEventListener('afterprint', function (event) {
	writeOutput("onaftereprint fired");
});

document.querySelector('button').addEventListener('click', function (event) {
	writeOutput("window.print called");
	window.print();
});