Skip to content

Instantly share code, notes, and snippets.

@0wwafa
Last active January 3, 2026 00:56
Show Gist options
  • Select an option

  • Save 0wwafa/6569915d936370656c687e014e596f4a to your computer and use it in GitHub Desktop.

Select an option

Save 0wwafa/6569915d936370656c687e014e596f4a to your computer and use it in GitHub Desktop.
Print / Export Claude Chat

Go to https://claude.ai/chat/new (or any other chat you had in the past).

Then run this code:

function printClaude() {   // (C) 2024 by ZeroWw. If you use this code, just give me some credit.
    const centralPart = document.querySelector('.flex-1.flex.flex-col.px-4.max-w-3xl.mx-auto.w-full.pt-1');

    if (centralPart) {
        // Expand all "show more" buttons
        document.querySelectorAll('button').forEach(button => {
            const text = button.textContent.toLowerCase();
            if (text.includes('show more') || text.includes('continue') || text.includes('expand')) {
                button.click();
            }
        });

        // Wait for content to expand
        setTimeout(() => {
            const printWindow = window.open('', '_blank', `width=${window.screen.width * 0.85},height=${window.screen.height * 0.85}`);

            if (!printWindow) {
                alert('Pop-up blocked! Please allow pop-ups for this site and try again.');
                return;
            }

            // Get page stylesheets
            const styles = Array.from(document.styleSheets).map(styleSheet => {
                try {
                    return Array.from(styleSheet.cssRules).map(rule => rule.cssText).join('\n');
                } catch (e) {
                    return '';
                }
            }).join('\n');
            
            // Essential color variables - must stay in HSL format
            const cssVars = `:root{--text-000:49 6.9% 5.5%;--text-100:49 19.6% 13.3%;--text-200:49 18.8% 20%;--text-300:49 9% 30%;--text-400:49 7% 37%;--text-500:51 7.5% 42.1%;--accent-main-000:15 52.7% 43.9%;--accent-main-100:16 53.8% 47.5%;--accent-main-200:15 55.6% 52.4%;--accent-secondary-000:210 74.2% 42.1%;--accent-secondary-100:210 74.8% 49.8%;--accent-secondary-200:210 74.8% 57%;--accent-secondary-900:210 68.8% 93.3%;--accent-pro-000:251 34.2% 33.3%;--accent-pro-100:251 40% 45.1%;--accent-pro-200:251 61% 72.2%;--accent-pro-900:253 33.3% 91.8%;--oncolor-100:0 0% 100%;--bg-000:60 6.7% 97.1%;--bg-100:50 23.1% 94.9%;--bg-200:49 26.8% 92%;--bg-300:49 25.8% 87.8%;--bg-400:46 28.3% 82%;--bg-500:47 27% 71%;--accent-main-900:15 48% 90.2%;--border-100:48 12.5% 39.2%;--border-200:48 12.5% 39.2%;--border-300:48 12.5% 39.2%;--oncolor-200:60 6.7% 97.1%;--oncolor-300:60 6.7% 97.1%;--border-400:48 12.5% 39.2%;--danger-000:5 74% 28%;--danger-100:5 73.9% 37.7%;--danger-200:5 49.5% 58%;--danger-900:0 40.3% 89%;--white:0 0% 100%;--black:0 0% 0%;--kraft:25 49.7% 66.5%;--book-cloth:15 52.3% 58%;--manilla:40 54% 82.9%}`;
            
            printWindow.document.write(`<html><head><title>Claude_${new Date().getTime()}</title><style>${cssVars}${styles}</style></head><body>${centralPart.innerHTML}</body></html>`);

            // Cleanup: remove UI elements not needed in print
            const firstLink = printWindow.document.getElementsByTagName('a')[0];
            if (firstLink) firstLink.parentElement.removeChild(firstLink);

            const replyBox = printWindow.document.getElementsByClassName('border-0.5 border-border-300 flex');
            if (replyBox.length > 0) {
                const last = replyBox[replyBox.length - 1];
                if (last) last.parentElement.removeChild(last);
            }

            ['absolute -bottom-0 -right-1.5 sm:right-2', 'absolute -bottom-0 left-[2.3rem]', 'sticky bottom-0 mx-auto w-full pt-6'].forEach(className => {
                Array.from(printWindow.document.getElementsByClassName(className)).forEach(elem => elem.parentElement.removeChild(elem));
            });

            setTimeout(() => printWindow.print(), 3000);
        }, 1000);
    } else {
        console.error('Central part not found!');
    }
}

printClaude();
@somaking-au
Copy link

Claude's HTML seems to have been updated. I have fixed the function and it works for me now, in both function form and bookmark form. I also made sure the "show more" links are clicked before printing so the entire prompt is shown. Here is the update:

function printClaude() {
    const centralPart = document.querySelector('.flex-1.flex.flex-col.px-4.max-w-3xl.mx-auto.w-full.pt-1');

    if (centralPart) {
        // Expand all "show more" buttons
        document.querySelectorAll('button').forEach(button => {
            const text = button.textContent.toLowerCase();
            if (text.includes('show more') || text.includes('continue') || text.includes('expand')) {
                button.click();
            }
        });

        // Wait for content to expand
        setTimeout(() => {
            const printWindow = window.open('', '_blank', `width=${window.screen.width * 0.85},height=${window.screen.height * 0.85}`);

            if (!printWindow) {
                alert('Pop-up blocked! Please allow pop-ups for this site and try again.');
                return;
            }

            // Get page stylesheets
            const styles = Array.from(document.styleSheets).map(styleSheet => {
                try {
                    return Array.from(styleSheet.cssRules).map(rule => rule.cssText).join('\n');
                } catch (e) {
                    return '';
                }
            }).join('\n');
            
            // Essential color variables - must stay in HSL format
            const cssVars = `:root{--text-000:49 6.9% 5.5%;--text-100:49 19.6% 13.3%;--text-200:49 18.8% 20%;--text-300:49 9% 30%;--text-400:49 7% 37%;--text-500:51 7.5% 42.1%;--accent-main-000:15 52.7% 43.9%;--accent-main-100:16 53.8% 47.5%;--accent-main-200:15 55.6% 52.4%;--accent-secondary-000:210 74.2% 42.1%;--accent-secondary-100:210 74.8% 49.8%;--accent-secondary-200:210 74.8% 57%;--accent-secondary-900:210 68.8% 93.3%;--accent-pro-000:251 34.2% 33.3%;--accent-pro-100:251 40% 45.1%;--accent-pro-200:251 61% 72.2%;--accent-pro-900:253 33.3% 91.8%;--oncolor-100:0 0% 100%;--bg-000:60 6.7% 97.1%;--bg-100:50 23.1% 94.9%;--bg-200:49 26.8% 92%;--bg-300:49 25.8% 87.8%;--bg-400:46 28.3% 82%;--bg-500:47 27% 71%;--accent-main-900:15 48% 90.2%;--border-100:48 12.5% 39.2%;--border-200:48 12.5% 39.2%;--border-300:48 12.5% 39.2%;--oncolor-200:60 6.7% 97.1%;--oncolor-300:60 6.7% 97.1%;--border-400:48 12.5% 39.2%;--danger-000:5 74% 28%;--danger-100:5 73.9% 37.7%;--danger-200:5 49.5% 58%;--danger-900:0 40.3% 89%;--white:0 0% 100%;--black:0 0% 0%;--kraft:25 49.7% 66.5%;--book-cloth:15 52.3% 58%;--manilla:40 54% 82.9%}`;
            
            printWindow.document.write(`<html><head><title>Claude_${new Date().getTime()}</title><style>${cssVars}${styles}</style></head><body>${centralPart.innerHTML}</body></html>`);

            // Cleanup: remove UI elements not needed in print
            const firstLink = printWindow.document.getElementsByTagName('a')[0];
            if (firstLink) firstLink.parentElement.removeChild(firstLink);

            const replyBox = printWindow.document.getElementsByClassName('border-0.5 border-border-300 flex');
            if (replyBox.length > 0) {
                const last = replyBox[replyBox.length - 1];
                if (last) last.parentElement.removeChild(last);
            }

            ['absolute -bottom-0 -right-1.5 sm:right-2', 'absolute -bottom-0 left-[2.3rem]', 'sticky bottom-0 mx-auto w-full pt-6'].forEach(className => {
                Array.from(printWindow.document.getElementsByClassName(className)).forEach(elem => elem.parentElement.removeChild(elem));
            });

            setTimeout(() => printWindow.print(), 3000);
        }, 1000);
    } else {
        console.error('Central part not found!');
    }
}

printClaude();

Here's the bookmarklet version:

javascript:(function(){const a=document.querySelector(".flex-1.flex.flex-col.px-4.max-w-3xl.mx-auto.w-full.pt-1");if(a){document.querySelectorAll("button").forEach(b=>{const c=b.textContent.toLowerCase();(c.includes("show more")||c.includes("continue")||c.includes("expand"))&&b.click()});setTimeout(()=>{const b=window.open("","_blank","width="+.85*window.screen.width+",height="+.85*window.screen.height);if(!b){alert("Pop-up blocked! Please allow pop-ups for this site and try again.");return}const c=Array.from(document.styleSheets).map(d=>{try{return Array.from(d.cssRules).map(e=>e.cssText).join("\n")}catch(e){return""}}).join("\n"),d=":root{--text-000:49 6.9% 5.5%;--text-100:49 19.6% 13.3%;--text-200:49 18.8% 20%;--text-300:49 9% 30%;--text-400:49 7% 37%;--text-500:51 7.5% 42.1%;--accent-main-000:15 52.7% 43.9%;--accent-main-100:16 53.8% 47.5%;--accent-main-200:15 55.6% 52.4%;--accent-secondary-000:210 74.2% 42.1%;--accent-secondary-100:210 74.8% 49.8%;--accent-secondary-200:210 74.8% 57%;--accent-secondary-900:210 68.8% 93.3%;--accent-pro-000:251 34.2% 33.3%;--accent-pro-100:251 40% 45.1%;--accent-pro-200:251 61% 72.2%;--accent-pro-900:253 33.3% 91.8%;--oncolor-100:0 0% 100%;--bg-000:60 6.7% 97.1%;--bg-100:50 23.1% 94.9%;--bg-200:49 26.8% 92%;--bg-300:49 25.8% 87.8%;--bg-400:46 28.3% 82%;--bg-500:47 27% 71%;--accent-main-900:15 48% 90.2%;--border-100:48 12.5% 39.2%;--border-200:48 12.5% 39.2%;--border-300:48 12.5% 39.2%;--oncolor-200:60 6.7% 97.1%;--oncolor-300:60 6.7% 97.1%;--border-400:48 12.5% 39.2%;--danger-000:5 74% 28%;--danger-100:5 73.9% 37.7%;--danger-200:5 49.5% 58%;--danger-900:0 40.3% 89%;--white:0 0% 100%;--black:0 0% 0%;--kraft:25 49.7% 66.5%;--book-cloth:15 52.3% 58%;--manilla:40 54% 82.9%}";b.document.write("<html><head><title>Claude_"+(new Date).getTime()+"</title><style>"+d+c+"</style></head><body>"+a.innerHTML+"</body></html>");const e=b.document.getElementsByTagName("a")[0];e&&e.parentElement.removeChild(e);const f=b.document.getElementsByClassName("border-0.5 border-border-300 flex");f.length>0&&f[f.length-1]&&f[f.length-1].parentElement.removeChild(f[f.length-1]);["absolute -bottom-0 -right-1.5 sm:right-2","absolute -bottom-0 left-[2.3rem]","sticky bottom-0 mx-auto w-full pt-6"].forEach(g=>Array.from(b.document.getElementsByClassName(g)).forEach(h=>h.parentElement.removeChild(h)));setTimeout(()=>b.print(),3e3)},1e3)}else console.error("Central part not found!")})();

@navaldroid
Copy link

Just tried your new version, works great again! Thanx!

@0wwafa
Copy link
Author

0wwafa commented Dec 30, 2025

Updated the code. thanks @somaking-au

@kinow
Copy link

kinow commented Jan 3, 2026

Worked for me today! Thanks a lot!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment