Get Message Sender HTML No Longer Working! What's Changed?

Need assistance to determine why the following action now fails which has been working for quite some time. Perhaps something changed in Gmail?

Execute a JavaScript in Google Chrome Action (v9.0.5)

Execute a JavaScript in Google Chrome.kmactions (937 B)

Could the following console errors observed when I Inspect the Sender's email address help explain the problem?

This works for me:
document.querySelector('h3 span span[email]').innerText;

If you want both the sender name and email address, you could use:

emailElem = document.querySelector('h3 span span[email]');
senderName = emailElem.innerText;
senderEmail = emailElem.getAttribute('email');

Given this HTML:

<table cellpadding="0" class="cf ix">
      <td class="c2">
      <h3 class="iw">
        <span class="qu" role="gridcell" tabindex="-1">
          <span email="" name="Xfinity" data-hovercard-id="" class="gD">Xfinity</span> 
          <span class="go">
            <span aria-hidden="true">&lt;</span>
            <span aria-hidden="true">&gt;</span>


Thanks, your response works so I'll modify all my macros to use it!!

If I'm not mistaken, you provided the original solution that used to work until today (i.e. document.getElementsByTagName("H3")[2].innerHTM;)

Any ideas what might have changed in either my Chrome or Gmail?

Most likely Gmail, but I have no specifics.


Could you also share the code to capture the message subject and body?

Because Google uses dynamic classes and very few attributes, these are identified mostly by position -- which is very fragile. The slightest change in the web page could break these statements.

So, NO guarantees!

subjectStr = document.querySelector('h2[data-thread-perm-id]').innerText;
bodyStr = document.querySelector('div[data-message-id] > div:nth-child(2) > div:nth-child(3)').innerText;
1 Like


They work as well!

Many thanks

1 Like

Ah webscraping, the last refuge... :slight_smile:

Actually I use it a lot as the preferred, first choice solution.

My concern is, of course, the stability of the HTML. A nice stable DOM is to be treasured.