Skip to content

Instantly share code, notes, and snippets.

@karbassi
Last active February 28, 2024 20:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save karbassi/d7499bf9da6407fde1ff45dcde582a12 to your computer and use it in GitHub Desktop.
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();
@thesterns
Copy link

hi, i what i was looking for, tnx/
but i get two errors:


Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'click')
at archive (:11:59)
at :17:1
archive @ VM177:11
(anonymous) @ VM177:17


Promise {: TypeError: Cannot read properties of undefined (reading 'click')
at archive (:11:59)…}
[[Prototype]]
:
Promise
[[PromiseState]]
:
"rejected"
[[PromiseResult]]
:
TypeError: Cannot read properties of undefined (reading 'click') at archive (:11:59) at :17:1
message
:
"Cannot read properties of undefined (reading 'click')"
stack
:
"TypeError: Cannot read properties of undefined (reading 'click')\n at archive (:11:59)\n at :17:1"
[[Prototype]]
:
Error
constructor
:
ƒ TypeError()
message
:
""
name
:
"TypeError"
[[Prototype]]
:
Object
constructor
:
ƒ Error()
message
:
""
name
:
"Error"
toString
:
ƒ toString()
length
:
0
name
:
"toString"
arguments
:
(...)
caller
:
(...)
[[Prototype]]
:
ƒ ()
apply
:
ƒ apply()
arguments
:
(...)
bind
:
ƒ bind()
call
:
ƒ call()
caller
:
(...)
constructor
:
ƒ Function()
length
:
0
name
:
""
toString
:
ƒ toString()
Symbol(Symbol.hasInstance)
:
ƒ Symbol.hasInstance
get arguments
:
ƒ ()
set arguments
:
ƒ ()
get caller
:
ƒ ()
set caller
:
ƒ ()
[[FunctionLocation]]
:

[[Prototype]]
:
Object
[[Prototype]]
:
Object

@karbassi
Copy link
Author

This is from Nov 4, 2019. I doubt the interface for Google Messages webapp is the same anymore.

@thesterns
Copy link

tnx for your reply. can you pls update the code above so it will work again?

@ishanarora
Copy link

@thesterns just replace button.mat-menu-item with button.mat-mdc-menu-item in the above code

@thesterns
Copy link

works great. thanks!

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