Contents

Bulk Delete Twitter Messages

Hey, are you leaving Twitter? Are you worried that with 80% of the staff gone, it’s just a matter of time until there start being unreported breaches? (Heck, maybe there have already!) Want to ensure anyone breaking into your account doesn’t read your messages? Have a bulk-delete script, on the house!

To use this, go to the messages page on a computer. Right click somewhere on the page, and choose “inspect” (Chrome) or “inspect element” (Firefox) to get the developer tools to come up. (If you’ve never seen that before, welcome to how so many of us learned to do things on the web!) In there, go to the tab labeled “Console.” Paste the following in and hit the enter or return key:

document.querySelectorAll("[aria-label='Timeline: Messages'] [aria-label=More]").forEach(button => {
        button.click();
        deleteOption = document.querySelector("[role=menu] [role=menuitem]:last-child");
        deleteOption.click();
        confirmation = document.querySelector("[data-testid='confirmationSheetConfirm']");
        confirmation.click()
     })

That’ll delete a “page” of messages, meaning however many messages Twitter pre-loaded before you scroll down. You’ll likely have to run it a few times if you were a heavy user of Twitter messages. I think I ran it 5 times.

Important note

This does not guarantee deletion from the servers, because the messages remain available to the other person you were chatting with. This is only helpful in the event someone specifically gets into your account.

Explanation

If you’d like to know how it works, let me break it down for you:

document.querySelectorAll("[aria-label='Timeline: Messages'] [aria-label=More]")

This line tells it to find all the buttons that, for accessibilty tools like screen readers, are labeled “More” within the section labeled “Timeline: Messages.”

The .forEach(button => {}) part is telling it that we’re going to go through those “More” buttons one at a time. The part inside the {} is what it’ll do for each one.

First, button.click(), it’ll click that button.

Then:

deleteOption = document.querySelector("[role=menu] [role=menuitem]:last-child");
deleteOption.click();

it’ll find the last menu item in the menu that pops up, and it’ll click that too. (That’s the menu option that says “Delete,” so I stored it in a variable named deleteOption.)

After that, a confirmation box pops up

confirmation = document.querySelector("[data-testid='confirmationSheetConfirm']");
confirmation.click()

This code grabs that confirmation box and finds the button that, for the purposes of their testing tools, was labeled confirmationSheetConfirm, and then it clicks on that too.

Happy deleting!