Skip to content

Instantly share code, notes, and snippets.

@karbassi
Last active October 17, 2025 15:50
Show Gist options
  • Select an option

  • Save karbassi/d7499bf9da6407fde1ff45dcde582a12 to your computer and use it in GitHub Desktop.

Select an option

Save karbassi/d7499bf9da6407fde1ff45dcde582a12 to your computer and use it in GitHub Desktop.
Archive all messages in Google Messages web app

Archive all messages in Google Messages web app

This code was something I quickly put together to archive over 5000 text messages in Google Messages. I have no idea if Google frowns on this or not, but it's basically the same as if a human sat there and archived all the messages by hand.

Tested and working as of Monday, November 4, 2019.

How to run

  1. Sign into https://messages.google.com/web/
  2. Open Chrome Developers console by going to View > Developer > JavaScript Console.
  3. Copy and paste the code below into console. It should automatically run.

Warning

Don't run any code before you know what it does. Review it and make sure it's safe. I accept no fault if something goes wrong. Google may change their code at anytime and this code may not work. I provide no support.

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function archive() {
let menu = document.querySelectorAll('button.menu-button');
console.log(menu.length);
if(menu.length) {
menu[0].click();
document.querySelectorAll('button.mat-mdc-menu-item')[0].click()
await sleep(1000);
archive();
}
}
archive();
@Rhynorater
Copy link

Fixed scroll:

// Global handle so you can stop scrolling manually
window.stopScrolling = () => {
  clearInterval(window.scrollIntervalId);
  console.log("⛔️ Auto-scroll manually stopped.");
};

(function scrollToLoadAll() {
  const container = document.querySelector(
    '.conversation-list'
  );

  if (!container) {
    console.error("❌ Scroll container not found.");
    return;
  }

  let lastScrollTop = -1;
  let triesWithoutChange = 0;
  const maxTries = 60; // 60 tries * 1000ms = ~1 minute

  window.scrollIntervalId = setInterval(() => {
    container.scrollTop += 500;
    console.log("↘️ Scrolling…", container.scrollTop);

    if (container.scrollTop === lastScrollTop) {
      triesWithoutChange++;
      if (triesWithoutChange >= maxTries) {
        clearInterval(window.scrollIntervalId);
        console.log("✅ Done: All conversations likely loaded.");
      }
    } else {
      lastScrollTop = container.scrollTop;
      triesWithoutChange = 0;
    }
  }, 1000);
})();

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