1

How do I use JavaScript to bulk delete all my Google Voice messages quickly?

4 Answers 4

1

Run this in your browser's JavaScript console:

// Code to be run at Legacy Google Voice
//  Run at: https://www.google.com/voice/b/0#history
//          https://www.google.com/voice/b/0#spam
//          https://www.google.com/voice/b/0#trash
function sleep(ms) { // courtesy: https://stackoverflow.com/a/39914235/1429450
    return new Promise(resolve => setTimeout(resolve, ms));
}
async function deleteMessages() {
    do {
        // Get message IDs.
        var msgs = document.getElementsByClassName("gc-message"),
            msgids = [];
        itemcount = msgs.length;
        for (var i = 0; i < itemcount; ++i) {
            msgids.push(msgs[i].id);
        };
        // Construct form. courtesy: https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects#Creating_a_FormData_object_from_scratch
        try {
            var formData = new FormData();
            for (var i in msgids) {
                formData.append("messages", msgids[i]);
            }
            formData.append("_rnr_se", _gcData["_rnr_se"]);
            var request = new XMLHttpRequest();
            request.open("POST", "https://www.google.com/voice/b/0/inbox/deleteForeverMessages/");
            request.send(formData);
        } catch (a) {
            return;
        }
        await sleep(1000);
        try {
            document.getElementById("gc-inbox-next").click();
        } catch (b) {
            try {
                document.getElementById("gc-inbox-prev").click();
            } catch (c) {
                continue;
            }
        }
        await sleep(1000);
    } while (itemcount != 0);
}
deleteMessages();
1
  • If you want to delete everything except the last x days, see my answer below.
    – alchemy
    Commented Apr 14, 2020 at 17:17
0

EDIT: it cycles through, but is not deleting..

Have only tested this on the 'Legacy' version of GV. Click 'Use Legacy'. It has the URL starting with 'https://www.google.com/voice' instead of 'voice.google.com'.

To delete everything except the last x days, click on Next Page at the bottom and the URL will change to have a 'inbox/p1' added a the end. Change the number until you find the page with the last messages you want to keep; I used 6 months ago.

@Geremia's code is great, but there is a typo, so delete the } above the second 'await sleep'. Also delete "try {document.getElementById("gc-inbox-prev").click();} catch (c) {", which deletes backwards in history up to the current moment.

Now press Ctrl+Shift+i or right click and click 'Inspect Source'. Click the Sources tab of the JS Console, then the >> arrows next to Page and Filesystem, and then Snippets. Paste the function code and press Ctrl+Enter to run. Press the pause icon also under sources to stop infinite loops. Also, you have to manually terminate it, by pressing Pause under Sources, or Ctrl+Esc and end process.

I started playing with this code, but got an 'undefined, when entering the variable to see how if it would work, without deleting everything "var msgs = document.getElementsByClassName("gc-message")". Per this Answer, it does that normally I guess because its not returning a value (https://stackoverflow.com/questions/24342748/why-does-console-log-say-undefined-and-then-the-correct-value). I got to where I needed to pause the while loop and went back to Geremias code. And then realized it would do what I wanted with minor manual page manipulation. But heres the code that was working to automatically go forward through each page until the correct date to start deleting. Geremias code works by deleting the whole page of messages and then reloading, so my code could work to find the starting point for that if anyone wants to complete it for others. Or you can just do it manually.

var dateLast = new Date(document.getElementsByClassName('gc-message-time')[0].innerText)
var dateNow = new Date()
var dateCutoff = new Date(dateNow - 30*24*60*60*1000)
while (dateLast > dateCutoff) {
    document.getElementById('gc-inbox-next').click(); 
    var dateLast = new Date(document.getElementsByClassName('gc-message-time')[0].innerText)
    await sleep(1000)
}

There is also this related Question: https://webapps.stackexchange.com/questions/55378/how-do-i-delete-text-messages-from-google-voice/

var msgs = document.getElementsByClassName("gc-message"), msgids = []; msgids
msgids.push(msgs[0].id)
var formData = new FormData()
formData.append("messages", msgids[0])
formData.append("_rnr_se", _gcData["_rnr_se"])
for (var pair of formData.entries()) {
    console.log(pair[0]+ ', ' + pair[1]); 
}
var request = new XMLHttpRequest();
request.open("POST", "https://www.google.com/voice/b/0/inbox/deleteForeverMessages/");
request.send(formData);

returns:.. POST https://www.google.com/voice/b/0/inbox/deleteForeverMessages/ 500

500 is an internal server error. I'll try a different approach..

0

Trying another approach on https://voice.google.com/u/1/voicemail?itemId=c.LONG_STRING and using WrapAPI. Once you get the long string ID, I think you can use it as the only content in a data header for a POST to: https://content.googleapis.com/voice/v1/voiceclient/thread/delete

Getting the IDs isnt easy. Ive tried document.querySelector("#messaging-view > div > md-content > div > gv-conversation-list > md-virtual-repeat-container > div > div.md-virtual-repeat-offsetter > div:nth-child(2) > div") and manually selecting it and this object comes up $0.$gvCtrlRef but I cant get the data-thread-id out of either except by innerHTML which I would have to parse to data-thread-id=.

I think after spending more than a day on this, its going to be easier to delete my entire account and just claim my number on another one.

It might be possible using Selenium, but I cant sign in because google says Chromedriver isnt secure. I've attempted several solutions described here: https://stackoverflow.com/a/61219342/4240654, with no success. New accounts seem to have less problem with this as described here (https://stackoverflow.com/questions/59380356/how-to-handle-browser-or-app-may-not-be-secure-issue-with-web-driver-selenium-py).

For reference, here are the relevant Google Support threads:

How to mass delete calls/messages from google voice https://support.google.com/voice/forum/AAAAjq5-_rM4iYc83j4mRo?hl=en

i wanna delete my entire google voice history. without it going to the trash https://support.google.com/voice/thread/6331069?hl=en

How do I Delete more than one phone call or text message? http://support.google.com/voice/thread/26118990?hl=en

-1

Should be able to script this using the keyboard shortcuts. # deletes the current message, but there is a confirmation dialog box. <Tab><Tab> selects the delete button, and <Enter> deletes the message, advancing to the next.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .