Skip to content

Instantly share code, notes, and snippets.

@adamveld12
Last active October 29, 2025 22:12
Show Gist options
  • Select an option

  • Save adamveld12/0a48496b6c873adf418fc3dda4d28007 to your computer and use it in GitHub Desktop.

Select an option

Save adamveld12/0a48496b6c873adf418fc3dda4d28007 to your computer and use it in GitHub Desktop.
Export Google Messages content from the browser app.
function collateMessages(){
const conversations = [];
const msgRegex = /^(?<sender>[\w\W]+) said: (?<content>[\w\W]+) (?:Sent|Received) on (?<date>[\w\d\s,]+) at (?<time>[\d\:\s]+(?:AM|PM))\.\s?(?<status>Delivered\.)?\s?(?<meta>.*)$/;
const msgEle = document.getElementsByTagName('mws-text-message-part');
console.log(`fetching ${msgEle.length} messages`);
for (var i = 0; i < msgEle.length; i++) {
const messageContent = msgEle.item(i).getAttribute('aria-label');
const matches = messageContent.match(msgRegex);
if (!matches?.groups) {
console.warn('this message is special', messageContent);
} else {
const { sender, content, date, time, status, meta } = matches.groups;
const t = new Date(`${date} ${time}`);
conversations.push({
sender,
content,
time: t.toString(),
timestamp: t.getTime(),
status,
meta,
});
}
}
console.log(`got ${conversations.length} messages`);
return conversations;
}
function downloadJSON(data, filename = 'data.json') {
const jsonString = JSON.stringify(data);
const blob = new Blob([jsonString], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
const msg = collateMessages();
downloadJSON(msg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment