Presently, the ChatGPT UI gets a bit weird when it comes to printing.
If you just try to print the page, it will print a single page with the currently visible part of the content. Not exactly useful if ChatGPT just wrote for you a couple of hundred lines of code.
If you try to first preselect its answer (or several answers, i.e., the part of the conversation that you wish to see printed), and then pick Selection in the (Chrome, Edge) print dialog, it prints the whole thing, but the code is now without line breaks and the page is badly formatted with a very large left margin.
Without further ado, if you first go into the JavaScript debugger and enter the following code, things will work:
var styleSheet = document.createElement("style");
styleSheet.innerText =
":not(pre)>code.hljs, :not(pre)>code[class*=language-] { white-space: pre-wrap !important; }";
styleSheet.innerText += " .xl\\:max-w-\\[48rem\\] { max-width: unset !important; }";
styleSheet.innerText +=
" @media (min-width: 1280px) { .xl\\:max-w-\\[48rem\\] { max-width: unset !important; } }";
styleSheet.innerText +=
" .max-w-\\[var\\(--user-chat-width\\,70\\%\\)\\] { max-width: 70% !important; }";
styleSheet.innerText += ".w-full { width: unset; min-width: 70%; }";
styleSheet.innerText += " .mb-2 {margin-bottom: .5rem; display: none !important; }";
document.head.appendChild(styleSheet);
This current update (February 2025) addresses both the code formatting and margin issues, but things can break anytime of course as OpenAI changes their UI design.