Skip to content

Instantly share code, notes, and snippets.

@gual
Last active June 14, 2021 03:17
Show Gist options
  • Save gual/1ee53af2588e84d29405b4ac7f90684c to your computer and use it in GitHub Desktop.
Save gual/1ee53af2588e84d29405b4ac7f90684c to your computer and use it in GitHub Desktop.
To export whatsapp chat history (text only)
// This needs to be run on the browser console with the corresponding chat selected
// on Whatsapp Web. It also needs to have the whole conversation loaded.
// It copies the conversation to the clipboard, change it as needed.
conversation = '';
msgElements = document.querySelectorAll('div.copyable-text:not(._2_1wd)');
for (let msgElement of msgElements) {
sender = msgElement.dataset.prePlainText;
try {
message = msgElement.querySelector('._3-8er.selectable-text.copyable-text span').innerText;
completeMsg = sender + message;
conversation += '\n' + completeMsg;
} catch (error) {
continue;
}
};
navigator.clipboard.writeText(conversation).then(function() {
console.log('success');
}, function(err) {
console.log('fail', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment