DEV Community

Yuki Shindo
Yuki Shindo

Posted on

This is a very small ChatGPT conversation downloader

Here is some code I wrote for a change of pace.
This is a small script intended to be pasted into the Chrome DevTools console.

I created it because I wanted to keep a text file of my conversations with ChatGPT.

With the ChatGPT page open, paste the following code onto Chrome DevTools and run it.

const download = () => {
  const title = document.querySelector('.pr-14.bg-gray-800').text;

  const textList = []
  document.querySelectorAll('.text-base').forEach((t, i) => {
    textList.push(`${i % 2 === 0 ? "Q:" : "A:"} ${t.textContent}`)
  })
  const text = textList.join('\n');

  const blob = new Blob([text], { type: "text/plain" });
  const url = URL.createObjectURL(blob);

  const a = document.createElement("a");
  a.href = url;
  a.download = title;
  document.body.appendChild(a);
  a.click();

  URL.revokeObjectURL(url);
}
Enter fullscreen mode Exit fullscreen mode

Next, select the conversation you want to download from the left menu.

ChatGPT left menu

After selecting the conversation, execute download() on the console of DevTools to download the content of the conversation as a text file.
The file name will be the title from the selected left menu.

There is one thing to note. This script will not work if the structure of ChatGPT page is updated.

The code is also saved in Gist.

ChatGPT conversation downloader(Gist)

Top comments (0)