Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save elibosley/6acb8850ad1f9f208c30d7c7e2842b89 to your computer and use it in GitHub Desktop.
Save elibosley/6acb8850ad1f9f208c30d7c7e2842b89 to your computer and use it in GitHub Desktop.
Archive all of the messages in your Facebook Messages Inbox

Facebook - Archive All Messages

Because who doesn't have an inbox full of "I got a new phone", event-based group chats, and old lingering messages in their Facebook Messages?

Surprisingly, Facebook has not implemented a way to archive many messages in your inbox. This script provides that solution.

UPDATE: THIS SCRIPT HAS BEEN UPDATED TO WORK AND IS TESTED AS WORKING (OCTOBER 31st, 2017 (spooky)). LET ME KNOW IF IT DOESN'T WORK FOR YOU!

Quickstart

Load Facebook Messages in a new tab.

Open the JavaScript console and paste the contents of jquery.min.js into the console.

Paste the contents of archive-all-facebook-messages.js into the console.

If you want to only test the results before actually running the archiving, there's a param for that:

archive_all(testOnly=true);

When you're ready to run for real:

archive_all();

Caveats

  • Currently only detects the list of messages visible to the user in the page. You can work around this by repeatedly scrolling the message list pane to the bottom until all messages are loaded. I plan to automate this step soon. (Maybe)
  • There is no way to whitelist certain messages from being archived. Currently, you can manually unarchive select messages from the archived view.
  • Sometimes the messages page remains cached after the script reloads it. Reloading it once by hand solves this.
function archive_all(testOnly) {
messages = $("._5blh")
console.log("Found", messages.length, "messages on messsenger.");
if (!testOnly) {
for (i = 0; i < messages.length; i++) {
try {
messages[i].click()// open dialog
$("li:contains('Archive')").last().click()
}
catch (TypeError) {
console.log("TypeError")
}
}
}
}
@Elise-Kiesje
Copy link

Elise-Kiesje commented Mar 26, 2019

This is really great! Thank you for creating! In your first message you indicate that you are working on a solution for scrolling down. I have messages of 9 years old and scrolling down is not possible :( so mutch are there.
Thanks in advance!

@MrMysakovich
Copy link

Hi, how to archive all messages? I tried it and it does not work

@surajk63
Copy link

It does works till today's date: Just stating the facts.

First open the facebook masseges in new tab, check the address bar, it should say only https://www.facebook.com/messages, if you found the link with some other conversation then archieve that manually first, and then process the following steps.
open the console panel by right clicking, and paste the jquery into the console, you will get true in return, and then copy the function from above (archive-all-facebook-messages.js) and copy the function call named as: archive_all();

@riginoommen
Copy link

This is not working reproducing the error

function archive_all(testOnly) {

    messages = $("._5blh")
    console.log("Found", messages.length, "messages on messsenger.");
    if (!testOnly) {
        for (i = 0; i < messages.length; i++) {
            try {
                messages[i].click()// open dialog
                $("li:contains('Archive')").last().click()
            }
            catch (TypeError) {
                console.log("TypeError")
            }
        }
    }
}
undefined
archive_all();
r03b3N9bqAO.js?_nc_x=v2Bw1ZTfcx6:118 Uncaught Error: <![EX[["Tried to get element with id of \"%s\" but it is not present on the page TAAL[1]","._5blh"]]]>
    at g (r03b3N9bqAO.js?_nc_x=v2Bw1ZTfcx6:118)
    at a [from $-core] (r03b3N9bqAO.js?_nc_x=v2Bw1ZTfcx6:118)
    at archive_all (<anonymous>:3:16)
    at <anonymous>:1:1
g @ r03b3N9bqAO.js?_nc_x=v2Bw1ZTfcx6:118
a [from $-core] @ r03b3N9bqAO.js?_nc_x=v2Bw1ZTfcx6:118
archive_all @ VM184:3
(anonymous) @ VM189:1

@elibosley
Copy link
Author

@riginoommen Make sure you load jquery by pasting it into the terminal before running the script.

@tracylemke
Copy link

Works like a charm! Thank you.

@hyiltiz
Copy link

hyiltiz commented Jan 20, 2020

Scripts provided above doesn't work anymore.

Steps

  1. disable adblockers etc.
  2. paste and run jquery.min.js in the console.
  3. paste and run archive_all function definition in the console.
  4. scroll the Facebook Messenger chat panel on the right to the bottom with mouse manually.
  5. run archive_all();

Result

Correctly reports finding several hundred items, and after a while returns undefined but nothing happens to the chat. Nothing changes even after a refresh.
Tested in up-to-date Firefox Developer Version or Chrome.

Fix

Facebook renamed Archive to Hide. Use this:

(function run() {
  let all = document.querySelectorAll('div[aria-label="Conversation actions"]');
  if (all.length == 0) return;
  let a = all[0];
  a.click();
  setTimeout(() => {
    document.querySelectorAll('a[role=menuitem]').forEach(act => {
      if (act.innerText.match(/Hide/)) act.click();
    });
    run();
  }, 250);
})();

Or this:

function archive_all(testOnly) {

    messages = $("._5blh")
    console.log("Found", messages.length, "messages on messsenger.");
    if (!testOnly) {
        for (i = 0; i < messages.length; i++) {
            try {
                messages[i].click()// open dialog
                $("li:contains('Hide')").last().click()
            }
            catch (TypeError) {
                console.log("TypeError")
            }
        }
    }
}
archive_all();

@riginoommen
Copy link

Scripts provided above doesn't work anymore.

Steps

  1. disable adblockers etc.
  2. paste and run jquery.min.js in the console.
  3. paste and run archive_all function definition in the console.
  4. scroll the Facebook Messenger chat panel on the right to the bottom with mouse manually.
  5. run archive_all();

Result

Correctly reports finding several hundred items, and after a while returns undefined but nothing happens to the chat. Nothing changes even after a refresh.
Tested in up-to-date Firefox Developer Version or Chrome.

Fix

Facebook renamed Archive to Hide. Use this:

(function run() {
  let all = document.querySelectorAll('div[aria-label="Conversation actions"]');
  if (all.length == 0) return;
  let a = all[0];
  a.click();
  setTimeout(() => {
    document.querySelectorAll('a[role=menuitem]').forEach(act => {
      if (act.innerText.match(/Hide/)) act.click();
    });
    run();
  }, 250);
})();

Or this:

function archive_all(testOnly) {

    messages = $("._5blh")
    console.log("Found", messages.length, "messages on messsenger.");
    if (!testOnly) {
        for (i = 0; i < messages.length; i++) {
            try {
                messages[i].click()// open dialog
                $("li:contains('Hide')").last().click()
            }
            catch (TypeError) {
                console.log("TypeError")
            }
        }
    }
}
archive_all();

New script works perfectly. Thanks

@szczepkacpra
Copy link

szczepkacpra commented Apr 19, 2020

I reproduced steps to the letter on Chrome's regular and Incognito mode (to rule out plugins interfering with the outcome) with no success.


Running archive_all(); on @hyiltiz 's code:

(function run() {
  let all = document.querySelectorAll('div[aria-label="Conversation actions"]');
  if (all.length == 0) return;
  let a = all[0];
  a.click();
  setTimeout(() => {
    document.querySelectorAll('a[role=menuitem]').forEach(act => {
      if (act.innerText.match(/Hide/)) act.click();
    });
    run();
  }, 250);
})();

returns:

VM1902:1 Uncaught ReferenceError: archive_all is not defined at <anonymous>:1:1

on both facebook.com/messages and messenger.com.


Running archive_all(); on on @hyiltiz 's code:

function archive_all(testOnly) {

    messages = $("._5blh")
    console.log("Found", messages.length, "messages on messsenger.");
    if (!testOnly) {
        for (i = 0; i < messages.length; i++) {
            try {
                messages[i].click()// open dialog
                $("li:contains('Hide')").last().click()
            }
            catch (TypeError) {
                console.log("TypeError")
            }
        }
    }
}
archive_all();

on facebook.com/messages console returns:

Found 0 messages on messsenger.
undefined

on messenger.com console returns:

Found 20 messages on messsenger.
undefined

The only hidden conversations, are those which I manually hide following @surajk63 instructions.

FIX:

Change Facebook's language to English

@surajk63
Copy link

Scripts provided above doesn't work anymore.

Steps

  1. disable adblockers etc.
  2. paste and run jquery.min.js in the console.
  3. paste and run archive_all function definition in the console.
  4. scroll the Facebook Messenger chat panel on the right to the bottom with mouse manually.
  5. run archive_all();

Result

Correctly reports finding several hundred items, and after a while returns undefined but nothing happens to the chat. Nothing changes even after a refresh.
Tested in up-to-date Firefox Developer Version or Chrome.

Fix

Facebook renamed Archive to Hide. Use this:

(function run() {
  let all = document.querySelectorAll('div[aria-label="Conversation actions"]');
  if (all.length == 0) return;
  let a = all[0];
  a.click();
  setTimeout(() => {
    document.querySelectorAll('a[role=menuitem]').forEach(act => {
      if (act.innerText.match(/Hide/)) act.click();
    });
    run();
  }, 250);
})();

Or this:

function archive_all(testOnly) {

    messages = $("._5blh")
    console.log("Found", messages.length, "messages on messsenger.");
    if (!testOnly) {
        for (i = 0; i < messages.length; i++) {
            try {
                messages[i].click()// open dialog
                $("li:contains('Hide')").last().click()
            }
            catch (TypeError) {
                console.log("TypeError")
            }
        }
    }
}
archive_all();

New script works perfectly. Thanks

Try this one again, it should work.
I just tried today and it is working perfectly.

@szczepkacpra
Copy link

Try this one again, it should work.
I just tried today and it is working perfectly.

Thanks for answering. You sent me the same codes I have tried and quoted in my question.

Did you use top or the bottom code?
Did you go to facebook.com/messages or messenger.com?
What browser are you using?

@surajk63
Copy link

Try this one again, it should work.
I just tried today and it is working perfectly.

Thanks for answering. You sent me the same codes I have tried and quoted in my question.

Did you use top or the bottom code?
Did you go to facebook.com/messages or messenger.com?
What browser are you using?

I used the second code, first you have to load jquery code and then this function.
Then you can call the function as many times as you required.
You can try on both link: facebook.com/messages or messenger.com on chrome latest browser.

Thanks
-Suraj

@szczepkacpra
Copy link

szczepkacpra commented Apr 20, 2020

I found the solution: Facebook language has to be set to English. Otherwise the script won't work.

Thanks for getting involved @surajk63

@elibosley could you please include this information in your description?

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