Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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")
}
}
}
}
@whatjackhasmade

This comment has been minimized.

Copy link

commented Nov 9, 2017

Flawless, thanks for the code and tutorial!

@jayceelo

This comment has been minimized.

Copy link

commented Nov 30, 2017

I got this error after running it the second time:
image

@andigeng

This comment has been minimized.

Copy link

commented Dec 19, 2017

You don't have jQuery. A janky way you can get around this is to literally copy paste jQuery.js into the console, and then execute the script.

https://code.jquery.com/jquery-3.2.1.js

@Mmilya

This comment has been minimized.

Copy link

commented Jan 9, 2018

it says "true" but didn't work...?

@tomsihap

This comment has been minimized.

Copy link

commented Feb 8, 2018

All good as of today!

@SouSouleBarbu

This comment has been minimized.

Copy link

commented Feb 12, 2018

To automate on every page, you need to add this function and to change "Afficher les plus anciens" by the text on the link to display the next messages in your own language.

function archive_andGoToNextPage(testOnly) {
	archive_all(testOnly);
	$('a').filter(function(index) { return $(this).text() === "Afficher les plus anciens"; })[0].click();
}

Then you need to call this:
setInterval(function(){ archive_andGoToNextPage(false); }, 3000);

@jlrumohr

This comment has been minimized.

Copy link

commented May 13, 2018

IT STILL WORKS! THANK YOU!

@rafuska

This comment has been minimized.

Copy link

commented Jun 17, 2018

Still working like a charm!
Thanks a lot :)

@yashvinawootar

This comment has been minimized.

Copy link

commented Jun 26, 2018

For french language, the text is currently "Voir la suite".

So the function should be as follows :

      function archive_andGoToNextPage(testOnly) {
      	archive_all(testOnly);
      	$('a').filter(function(index) { return $(this).text() === "Voir la suite"; })[0].click();
      }

And yes, it works wonderfully. The script has been running for the last couple of minutes and has already archived hundreds of messages ;)
Thanks a lot!

@ThomDap

This comment has been minimized.

Copy link

commented Jul 7, 2018

Thanks a lot !

@oswinrodrigues

This comment has been minimized.

Copy link

commented Oct 6, 2018

Amazing! Life-saver. Only thing that was non-intuitive was learning that I had to wait while the code did its thing in the background for large numbers of messages; during that time, it didn't look like anything was happening due to inactivity in the foreground. I clued in when I tried to refresh my tab and it stopped responding. Then trying it on a smaller number of messages showed the proportional lag involved. Stil, thanks so much!

@sefrijn

This comment has been minimized.

Copy link

commented Oct 10, 2018

screen shot 2018-10-09 at 17 06 00
Beware of using this script! Big problem after using it. My Facebook Messenger is broken: Now it just shows an empty white screen after archiving a lot of messages. It doesn't work anymore in any browser or any laptop. Works oke on my phone.
Did anybody else have this problem?
Or does somebody know how to fix it?

This is the error message I get in Chrome console:
ErrorUtils caught an error: "Cannot read property 'count' of undefined". Subsequent errors won't be logged; see https://fburl.com/debugjs. reportError @ -vtndqSSWSu.js:61

UPDATE - So just after posting this, it started working. Hmmm. Strange. Messenger.com was blank for about 48 hours.

@davidedmonson

This comment has been minimized.

Copy link

commented Oct 26, 2018

I just wanted to state for the record, this worked perfectly. Thank you.

@Debesyla

This comment has been minimized.

Copy link

commented Dec 26, 2018

For some reason it just throws back gray "undefined" without any other errors?
2018-12-26 17_10_16-devtools - www facebook com_messages_t_1472549906178974

@inigolv

This comment has been minimized.

Copy link

commented Feb 26, 2019

Got the same "Undefined" messages. Anyone knows how it might be fixed?

@ItsDevEmilio

This comment has been minimized.

Copy link

commented Mar 11, 2019

It still works, you just gotta paste jquery first, then the archive-all.js, and then you just have to type

archive_all();

And it archives all. Working as of 10-March-2019.

@Elise-Kiesje

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented May 17, 2019

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

@surajk63

This comment has been minimized.

Copy link

commented Jul 11, 2019

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.