Skip to content

Instantly share code, notes, and snippets.

@jrmessias
Created March 26, 2025 03:01
Show Gist options
  • Save jrmessias/1e248f69c4d94838da9ab3efaa9a8e3d to your computer and use it in GitHub Desktop.
Save jrmessias/1e248f69c4d94838da9ab3efaa9a8e3d to your computer and use it in GitHub Desktop.
Export Grok iA to PDF

To print a GROK chat, paste this code in javascript console:

(function() {
    var a = document.querySelector("body > div.flex > div").children[0].children[1].children[0];
    if (a) {
        const b = window.open("", "_blank", `width=${.85 * window.screen.width},height=${.85 * window.screen.height},left=${.075 * window.screen.width},top=${.045 * window.screen.height}`)
          , e = Array.from(document.styleSheets).map(c => {
            try {
                return Array.from(c.cssRules).map(d => d.cssText).join("\n")
            } catch (d) {
                return console.error("Error occurred while getting stylesheet rules", d),
                ""
            }
        }
        ).join("\n");
        b.document.write("<html><head><title>Grok_" + (new Date).getTime() + "</title>");
        b.document.write("<style>" + e + "</style>");
        b.document.write("</head><body>");
        b.document.write(a.innerHTML);
        b.document.write("</body></html>");
        setTimeout(b.print.bind(b), 3E3)
    } else
        console.error("Central part not found!")
}
)()

Alternatively, save a bookmark called "Print Grok" with the following code:

javascript:(function(){var a=document.querySelector("body > div.flex > div").children[0].children[1].children[0];if(a){const b=window.open("","_blank",`width=${.85*window.screen.width},height=${.85*window.screen.height},left=${.075*window.screen.width},top=${.045*window.screen.height}`),e=Array.from(document.styleSheets).map(c=>{try{return Array.from(c.cssRules).map(d=>d.cssText).join("\n")}catch(d){return console.error("Error occurred while getting stylesheet rules",d),""}}).join("\n");b.document.write("<html><head><title>Grok_"+(new Date).getTime()+"</title>"),b.document.write("<style>"+e+"</style>"),b.document.write("</head><body>"),b.document.write(a.innerHTML),b.document.write("</body></html>"),setTimeout(b.print.bind(b),3E3)}else console.error("Central part not found!")})()

Enjoy.

Note: If you want also the thinking to be printed, click on the thinking box before executing the bookmarklet (or the function).

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