Skip to content

Instantly share code, notes, and snippets.

@muuvmuuv
Last active December 4, 2025 10:33
Show Gist options
  • Select an option

  • Save muuvmuuv/ff2d8506058e5adefa6fa2a1941372c1 to your computer and use it in GitHub Desktop.

Select an option

Save muuvmuuv/ff2d8506058e5adefa6fa2a1941372c1 to your computer and use it in GitHub Desktop.
Instagram messages mass delete
// Delete Instagram chat messages using "unsend".
//
// Thanks to: https://github.com/mahdixmohammad/instapurge/blob/main/main.js
console.clear()
const conversation = document.getElementsByClassName("x78zum5 xdt5ytf x1iyjqo2 xs83m0k x1xzczws x6ikm8r x1odjw0f x1n2onr6 xh8yej3 x16o0dkt")[0];
console.log("Conversation window", conversation)
conversation.scrollTo(-1)
deleteChats().then(console.log).catch(console.error);
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function deleteMessage(conversation, lastMessage) {
console.log("------------")
console.log("Deleting", lastMessage)
lastMessage.scrollIntoView({
block: "center",
behavior: "instant",
container: "nearest"
});
await delay(200);
// dispatch a mouseover event (i.e. hover beside the message)
lastMessage.dispatchEvent(new MouseEvent("mouseover",{
view: window,
bubbles: true,
cancelable: true,
}));
await delay(75);
let options = lastMessage.getElementsByClassName("x6s0dn4 x78zum5 xdt5ytf xl56j7k");
if (options.length === 0) {
console.warn("No options in", lastMessage)
conversation.click();
return
}
console.log("All options", options)
let option = options[options.length - 1];
let optionText = option.querySelector("title").textContent.toLowerCase()
if (!(optionText.includes("more") || optionText.includes("mehr"))) {
// skip stuff like timestamps inbetween messages
console.warn("Maybe timestamp")
conversation.click();
return
}
option.click();
await delay(75);
// the following selector returns a list of HTML Elements
// namely the span elements "Time"[0], "Forward"[1], "Copy"[2], and "Unsend"[3]
let moreUI = document.getElementsByClassName("html-div xdj266r x14z9mp xat24cr x1lziwak xexx8yu xyri2b x18d9i69 x1c1uobl x9f619 xjbqb8w x78zum5 x15mokao x1ga7v0g x16uus16 xbiv7yw x1uhb9sk x1plvlek xryxfnj x1iyjqo2 x2lwn1j xeuugli xdt5ytf xqjyukv x1cy8zhl x1oa3qoh x1nhvcw1");
console.log("More ui", moreUI)
let button = moreUI[moreUI.length - 1];
console.log("More ui button", button)
let unsendOrReport = button.querySelector("span").getElementsByClassName("x1lliihq x193iq5w x6ikm8r x10wlt62 xlyipyv xuxw1ft");
console.log("More ui unsend", unsendOrReport)
let unsendOrReportText = unsendOrReport[0].innerText.toLowerCase()
if (unsendOrReportText.includes("unsend") || unsendOrReportText.includes("zurückrufen")) {
// unsend
button.click();
await delay(200);
// unsend popup
let popupUnsendButton = document.getElementsByClassName("xjbqb8w x1qhh985 x10w94by x14e42zd x1yvgwvq x13fuv20 x178xt8z x1ypdohk xvs91rp x1evy7pa xdj266r x14z9mp xat24cr x1lziwak x1wxaq2x x1iorvi4 xf159sx xjkvuk6 xmzvs34 x2b8uid x87ps6o xxymvpz xh8yej3 x52vrxo x4gyw5p xkmlbd1 x1xlr1w8")[0]
popupUnsendButton.click();
await delay(300);
} else {
// focus the conversation
conversation.click();
await delay(100);
}
}
let seenElements = new WeakSet()
async function deleteChats() {
console.clear()
const messagesList = conversation.querySelectorAll('[data-release-focus-from="CLICK"]');
const messages = [...messagesList]
console.log("Messages", messages)
if (messages.length === 0) {
return
}
let hasError = false
while (messages.length > 0) {
try {
const message = messages.pop()
if (seenElements.has(message)) {
continue
}
seenElements.add(message)
await deleteMessage(conversation, message);
} catch (error) {
console.error(error)
hasError = true
break;
}
}
if (hasError) {
console.error("An error happened")
return
}
conversation.scrollBy(0, -100);
await delay(500)
await deleteChats()
}
@muuvmuuv
Copy link
Author

muuvmuuv commented Dec 4, 2025

Usage:
image

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