Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LinkedIn: Delete Messages (April 2020)

What

LinkedIn is a valuable resource, but sometimes it sucks. One of those times is when you want to delete messages. You have to select each message one by one. It takes about 4 "clicks" to successfully delete a message.

This script should help. Since LI requires you to perform multiple steps, I decided to automate it for you. Once you initiate the script, it will run every second. If a message has the ability to be deleted, it will be. If not, it will be archived. Some "InMail" messages cannot be deleted on the web app. This script should work as long as LI doesn't change their page layout or element names, which will happen eventually.

Last tested: April, 29, 2020

Setup & Cavets

  1. Since we use word matching, make sure to update the ARCHIVE and DELETE vars to your language.
  2. Some people only want to Archive and not Delete the messages, select this by updating the METHOD var.
  3. BEFORE pasting the script, make sure you've manually scrolled as far as you can so more messages are loaded, and you've clicked on one of the messages so the message contant pane is visible.
  4. You need to stay on the screen until it completes. It takes about 1 second per message. There is the possibility to speed it up, but this is the time that I found let each request be successful. Also, deleting takes a bit longer.
  5. It can only delete messages that are in the current view. You have two options here:
  • Before pasting the script, scroll down your message list to reveal all messages
  • Run the script till the page is empty, then refresh and run it again.
  • Personally, I found that any more than about 200 messages caused the page to run super slow.

How

  1. Go to the messages screen: LinkedIn Messages
  2. Open up your Chrome Console*
  3. Paste the following in the console

* if you are not sure what this is, then this script is not for you.

(function() {

  // Set Your Language Here
  const ARCHIVE = "Archive";
  const DELETE = "Delete";


  // Would you like to Archive them or Delete messages?
  // Archive = 1, Delete = 2
  const METHOD = 1;


  const goneFn = () => {
    const timer = setInterval(() => {
      const dropdown = document.querySelector('.msg-thread-actions__control');

      if (!dropdown) return clearInterval(timer);


      dropdown.click(); // Opens Up Menu

      const dropdownItems = document.querySelectorAll('.msg-thread-actions__dropdown-option');

      for (let i = 0; i < dropdownItems.length; i++) {
        let txt = dropdownItems[i].textContent.trim();

        // Delete Items
        if (txt === DELETE && METHOD === 2){
          dropdownItems[i].click();
          setTimeout(() => {
            const frame = document.querySelector('.msg-modal-delete-convo');
            const delBtn = frame.querySelector('.artdeco-button--primary');
            delBtn.click();
          }, 500);
        }

        // Archive Them Instead
        if (txt === ARCHIVE && METHOD === 1) {
          dropdownItems[i].click();
        }
      }
    }, 1000);
  };
  goneFn();
})();
@Talhah

This comment has been minimized.

Copy link

Talhah commented Feb 7, 2019

This is fantastic and worked like a charm. Thank you.

@amathenge

This comment has been minimized.

Copy link

amathenge commented Apr 28, 2019

Thank you for the script. It worked well.

@asifnauman

This comment has been minimized.

Copy link

asifnauman commented May 9, 2019

It actually does not delete the messages but moves to Archive and vice versa.

@n00bgit

This comment has been minimized.

Copy link

n00bgit commented May 15, 2019

It actually does not delete the messages but moves to Archive and vice versa.

Worked for me, just had to do it a few times because it deleted in blocks, until the next batch refreshed. Nothing moved to archive - everything remained in 'my connections'.

Thank you @twhitacre

@twhitacre

This comment has been minimized.

Copy link
Owner Author

twhitacre commented May 15, 2019

It actually does not delete the messages but moves to Archive and vice versa.

@asifnauman it will only delete messages that LinkedIn allows to be deleted. If they are "InMail" messages, they can only be archived.

Also worth noting, I'm on the free tier of LInkedIn. I'm not sure what the message section looks like if you upgrade. That might alter the way things are handled.

@Brindeau

This comment has been minimized.

Copy link

Brindeau commented Jun 9, 2019

Is there any way to write a similar script to delete messages containing a certain text ?

@twhitacre

This comment has been minimized.

Copy link
Owner Author

twhitacre commented Jun 10, 2019

@Brindeau sure, before you delete the message, just check for the text inside of the content.

@tjgilmore

This comment has been minimized.

Copy link

tjgilmore commented Jul 26, 2019

If you happen to be using LinkedIn Recruiter, this is what worked for me:

$("a.conversation-link").each(function() { $(this).click(); $("button.toggle-archive-button").click(); });

LinkedIn Recruiter has different element names and whatnot, so the script that worked in the normal version of LinkedIn didn't work. I ran that in the Chrome console and while it was kinda janky (after messages on the left quit moving/spasming, I had to reload the page, and at one point got an "insufficient resources" error in the console) it powered through 1.5 years of LinkedIn Recruiter InMail messages in about 75 seconds and 5 or 6 pages refreshes.

Disclaimer - I am 0% a coder and probably could have manually clicked the archive button on every message in the time it took me to find this code online and then try a bunch of different element names until something finally happened. If anyone wants to make the script prettier or better, by all means please do!

edit - credit to the original code that I modified for LinkedIn Recruiter: https://www.linkedin.com/pulse/how-delete-multiple-messages-from-your-linkedin-inbox-ted-wodoslawsky/

@christopherhelbert

This comment has been minimized.

Copy link

christopherhelbert commented Jul 29, 2019

This was absolutely awesome. Deleted hundreds of old messages.

@erikr

This comment has been minimized.

Copy link

erikr commented Jul 31, 2019

This saved me a lot of time. Thanks!

@bm4cs

This comment has been minimized.

Copy link

bm4cs commented Aug 3, 2019

Works like a charm 🙏

@c-hri-s

This comment has been minimized.

Copy link

c-hri-s commented Oct 9, 2019

Doesn't work as of 9 Oct 2019

Uncaught ReferenceError: $ is not defined
at :4:5

@twhitacre

This comment has been minimized.

Copy link
Owner Author

twhitacre commented Oct 9, 2019

Thanks for the feedback @c-hri-s - it looks like they removed jQuery as a dependency.

I updated the script as such and re-tested it. Seems to be working now.

@c-hri-s

This comment has been minimized.

Copy link

c-hri-s commented Oct 9, 2019

Thanks, can confirm it works perfectly now.
Really appreciate your effort, it's saved me hundreds of key presses!

@wauwturrr

This comment has been minimized.

Copy link

wauwturrr commented Oct 22, 2019

I'm getting the following error:

VM3098:20 Uncaught TypeError: Cannot read property 'click' of null
at :20:30

@folsomwg

This comment has been minimized.

Copy link

folsomwg commented Nov 3, 2019

I'm getting the following error:

VM3098:20 Uncaught TypeError: Cannot read property 'click' of null
at :20:30

Be sure you select the top message in your inbox thing on the left so the little "..." is on the DOM. @wauwturrr

Its funny, I asked LinkedIn support to nuke my inbox and they wouldn't do it. 🤔

@wauwturrr

This comment has been minimized.

Copy link

wauwturrr commented Nov 4, 2019

I'm getting the following error:
VM3098:20 Uncaught TypeError: Cannot read property 'click' of null
at :20:30

Be sure you select the top message in your inbox thing on the left so the little "..." is on the DOM. @wauwturrr

Its funny, I asked LinkedIn support to nuke my inbox and they wouldn't do it. 🤔

I've selected the first message, but still the same error...

@twhitacre

This comment has been minimized.

Copy link
Owner Author

twhitacre commented Nov 4, 2019

@wauwturrr I just checked and verified that it still works.

Make sure you are on this URL -> https://www.linkedin.com/messaging, then paste the script in.

That error shows up when you don't have any messages, or are on the wrong page. It is possible based on the type of account you have that the layout is different.

@wauwturrr

This comment has been minimized.

Copy link

wauwturrr commented Nov 4, 2019

@wauwturrr I just checked and verified that it still works.

Make sure you are on this URL -> https://www.linkedin.com/messaging, then paste the script in.

That error shows up when you don't have any messages, or are on the wrong page. It is possible based on the type of account you have that the layout is different.

When i go to the link, it makes the url: https://www.linkedin.com/messaging/thread/6597062970554089472/
Shoud that be the problem? There's no way to skip that.

@sfdcmx

This comment has been minimized.

Copy link

sfdcmx commented Nov 10, 2019

AMAZING!!!! Worked for me overall. Will share and also not happy how LinkedIn says it is possible to delete messages in bulk here: https://www.linkedin.com/help/linkedin/answer/420/deleting-a-conversation?lang=en

Not cool LinkedIn.

@mikeSGman

This comment has been minimized.

Copy link

mikeSGman commented Nov 21, 2019

Works as of Nov, 2019 with a few errors in the console; it works though! Thank you. (I have a free account, not recruiter nor paid for)

@Nick-Bowles

This comment has been minimized.

Copy link

Nick-Bowles commented Nov 28, 2019

Perfect, just needed to click in the messages pane, nice one

@igorissen

This comment has been minimized.

Copy link

igorissen commented Dec 8, 2019

First of all, a big thank you for your script!!
I've tweaked it a little. You've left the interval running.

(function() {
  const deleteFn = () => {
    let elCard = document.querySelector(".msg-conversation-listitem");
    //console.log(elCard);
    if (!elCard) {
      return setTimeout(() => {
        alert("No more message to delete");
      }, 250);
    }
    elCard.click();

    setTimeout(() => {
      let deleted = false;
      let dropdownItems = document.querySelectorAll("artdeco-dropdown-item");

      for (let i = 0; i < dropdownItems.length; i++) {
        let txt = dropdownItems[i].textContent.trim();
        switch (txt) {
          // add the word in your language
          case "Delete":
          case "Supprimer":
            deleted = true;
            dropdownItems[i].click();
            break;
        }
      }

      if (!deleted) return deleteFn();

      setTimeout(() => {
        let messageModal = document.querySelector(".msg-modal-delete-convo");
        if (!messageModal) return;

        let deleteBtn = messageModal.querySelector(".artdeco-button--primary");
        if (!deleteBtn) return;

        deleteBtn.click();
        deleteFn();
      }, 500);
    }, 1000);
  };

  deleteFn();
})();
@michaelvickersuk

This comment has been minimized.

Copy link

michaelvickersuk commented Dec 12, 2019

Great work, many thanks 👍

@cnolimit

This comment has been minimized.

Copy link

cnolimit commented Jan 12, 2020

Great work thanks! 👍🏾

@wolkanca

This comment has been minimized.

Copy link

wolkanca commented Jan 16, 2020

First of all, a big thank you for your script!!
I've tweaked it a little. You've left the interval running.

(function() {
  const deleteFn = () => {
    let elCard = document.querySelector(".msg-conversation-listitem");
    //console.log(elCard);
    if (!elCard) {
      return setTimeout(() => {
        alert("No more message to delete");
      }, 250);
    }
    elCard.click();

    setTimeout(() => {
      let deleted = false;
      let dropdownItems = document.querySelectorAll("artdeco-dropdown-item");

      for (let i = 0; i < dropdownItems.length; i++) {
        let txt = dropdownItems[i].textContent.trim();
        switch (txt) {
          // add the word in your language
          case "Delete":
          case "Supprimer":
            deleted = true;
            dropdownItems[i].click();
            break;
        }
      }

      if (!deleted) return deleteFn();

      setTimeout(() => {
        let messageModal = document.querySelector(".msg-modal-delete-convo");
        if (!messageModal) return;

        let deleteBtn = messageModal.querySelector(".artdeco-button--primary");
        if (!deleteBtn) return;

        deleteBtn.click();
        deleteFn();
      }, 500);
    }, 1000);
  };

  deleteFn();
})();

Thank you.

@DBJDBJ

This comment has been minimized.

Copy link

DBJDBJ commented Feb 1, 2020

This works as of 2020 FEB 01
This also works from latest Opera as of the same date

@aixstudio

This comment has been minimized.

Copy link

aixstudio commented Feb 13, 2020

This worked so well on Chrome, I had to remove messages from 2010 to now. 10 yrs took 30 mins, if done by fingers, many boring hrs. I wanted to clean up the message box as it's so cluttered with mostly junk requests from recruiters and promoters. I normally communicate with LinkedIn connections on emails.

@DBJDBJ

This comment has been minimized.

Copy link

DBJDBJ commented Feb 13, 2020

I also have a naughty script that deletes all contacts ...

@marioakamine

This comment has been minimized.

Copy link

marioakamine commented Feb 20, 2020

First of all, a big thank you for your script!!
I've tweaked it a little. You've left the interval running.

(function() {
  const deleteFn = () => {
    let elCard = document.querySelector(".msg-conversation-listitem");
    //console.log(elCard);
    if (!elCard) {
      return setTimeout(() => {
        alert("No more message to delete");
      }, 250);
    }
    elCard.click();

    setTimeout(() => {
      let deleted = false;
      let dropdownItems = document.querySelectorAll("artdeco-dropdown-item");

      for (let i = 0; i < dropdownItems.length; i++) {
        let txt = dropdownItems[i].textContent.trim();
        switch (txt) {
          // add the word in your language
          case "Delete":
          case "Supprimer":
            deleted = true;
            dropdownItems[i].click();
            break;
        }
      }

      if (!deleted) return deleteFn();

      setTimeout(() => {
        let messageModal = document.querySelector(".msg-modal-delete-convo");
        if (!messageModal) return;

        let deleteBtn = messageModal.querySelector(".artdeco-button--primary");
        if (!deleteBtn) return;

        deleteBtn.click();
        deleteFn();
      }, 500);
    }, 1000);
  };

  deleteFn();
})();

Thank you.

Obrigado!

@FrederikLi

This comment has been minimized.

Copy link

FrederikLi commented Feb 21, 2020

Didn't work for me as the css classes seem to have changed. Here's the version I used to archive all convos:

(function() {
  const archiveFn = () => {
    let elCard = document.querySelector(".msg-conversation-listitem");
    //console.log(elCard);
    if (!elCard) {
      return setTimeout(() => {
        alert("No more message to archive");
      }, 250);
    }
    elCard.click();

    setTimeout(() => {
      let archived = false;
      let dropdownItems = document.querySelectorAll("artdeco-dropdown-item");

      for (let i = 0; i < dropdownItems.length; i++) {
        let txt = dropdownItems[i].textContent.trim();
        switch (txt) {
          // add the word in your language
          case "Archivieren":
            archived = true;
            dropdownItems[i].click();
            break;
        }
      }

      if (!archived) return archiveFn();

      setTimeout(() => {
        let messageModal = document.querySelector(".msg-conversation-card__toggle-archive-btn");
        if (!messageModal) return;

        let archiveBtn = messageModal.querySelector(".artdeco-button__icon");
        if (!archiveBtn) return;

        archiveBtn.click();
        archiveFn();
      }, 500);
    }, 1000);
  };

  archiveFn();
})();
@nikkid1968

This comment has been minimized.

Copy link

nikkid1968 commented Mar 22, 2020

Not all heros wear capes! For all of you that provided code (the 2nd one worked awesome for me), thank you x1000!

@analyticsthatprofit

This comment has been minimized.

Copy link

analyticsthatprofit commented Apr 5, 2020

My new BFF! Thank you. This is extremely valuable as LinkedIn has become very spammy.

@HaiderZaidiDev

This comment has been minimized.

Copy link

HaiderZaidiDev commented Apr 9, 2020

Worked excellently, thank you.

@jamallmahmoudi

This comment has been minimized.

Copy link

jamallmahmoudi commented Apr 15, 2020

very good ### work thanks.

@aaliyahdxb

This comment has been minimized.

Copy link

aaliyahdxb commented Apr 18, 2020

Thank you. Worked!

@nonstop-paul

This comment has been minimized.

Copy link

nonstop-paul commented Apr 22, 2020

great... is there a similar macro for Posts?

@Lidia-Cordeiro

This comment has been minimized.

Copy link

Lidia-Cordeiro commented Apr 24, 2020

I can't seem to make it work;
VM446:20 Uncaught TypeError: Cannot read property 'click' of null
at :20:30

@mikeSGman

This comment has been minimized.

Copy link

mikeSGman commented Apr 28, 2020

Thank you. Worked!

How did you get it to work? I used it last year and it worked wonderfully. Today, whether in Chrome or FF with or without AdBlocker running its a no go.

@YannBrrd

This comment has been minimized.

Copy link

YannBrrd commented Apr 29, 2020

Hello,

Just yields "Undefined". How can it be debugged?

@twhitacre

This comment has been minimized.

Copy link
Owner Author

twhitacre commented Apr 29, 2020

@YannBrrd @mikeSGman @Lidia-Cordeiro

The script has just been updated. Please note that LinkedIn changes their class names and elements every few months. Feel free to look through what others are doing or adjust and pasted your updated script here. I'll try to keep it up to date, but I don't always have the time.

@YannBrrd

This comment has been minimized.

Copy link

YannBrrd commented May 7, 2020

Worked like a charm, thanks!

Capture d’écran 2020-05-07 à 13 51 55

@postlogs

This comment has been minimized.

Copy link

postlogs commented Jun 5, 2020

please mine only delete 3 message..please how do i delete all message

@batyacomunale

This comment has been minimized.

Copy link

batyacomunale commented Jun 24, 2020

i am not able to work it out - it works for me a few weeks back but not today - please help

@batyacomunale

This comment has been minimized.

Copy link

batyacomunale commented Jun 25, 2020

HELLLLLLPPP ITS NOT WORKING WHAT IS THE PROBLEM?

@twhitacre

This comment has been minimized.

Copy link
Owner Author

twhitacre commented Jun 25, 2020

@batyacomunale sorry it's not working. LinkedIn updates their HTML every so often which can break it. I've not tested it since about April and with how fast they push code, it has likely changed.

My guess is its something to do with the click of the dropdown tag, but I won't have time to look into it for a few days. Feel free to check that part out and see if you can figure it out!

@batyacomunale

This comment has been minimized.

Copy link

batyacomunale commented Jun 25, 2020

twhitacre Thank you so much for your response you are awsome

@batyacomunale

This comment has been minimized.

Copy link

batyacomunale commented Jul 20, 2020

Guys any update ?

@batyacomunale

This comment has been minimized.

Copy link

batyacomunale commented Jul 20, 2020

@YannBrrd @mikeSGman @Lidia-Cordeiro

The script has just been updated. Please note that LinkedIn changes their class names and elements every few months. Feel free to look through what others are doing or adjust and pasted your updated script here. I'll try to keep it up to date, but I don't always have the time.

hi there any update? i need it so badly

@batyacomunale

This comment has been minimized.

Copy link

batyacomunale commented Jul 31, 2020

@batyacomunale sorry it's not working. LinkedIn updates their HTML every so often which can break it. I've not tested it since about April and with how fast they push code, it has likely changed.

My guess is its something to do with the click of the dropdown tag, but I won't have time to look into it for a few days. Feel free to check that part out and see if you can figure it out!

hi how are you ? I NEED YOUR HELP

@twhitacre

This comment has been minimized.

Copy link
Owner Author

twhitacre commented Jul 31, 2020

@batyacomunale sorry, I've not had any time to work on this and don't anticipate time soon.

Please feel free to edit the script and post your findings, but it might be a while before I or others have time to make an update.

@batyacomunale

This comment has been minimized.

Copy link

batyacomunale commented Jul 31, 2020

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.