gmail.js icon indicating copy to clipboard operation
gmail.js copied to clipboard

Getting Unread Emails: Cannot read properties of undefined (reading 'title')

Open becomingmountains opened this issue 1 year ago • 4 comments

Calling gmail.get.unread_emails() gives me the following error:

gmail.js:649 Uncaught TypeError: Cannot read properties of undefined (reading 'title')
    at Gmail.api.helper.get.navigation_count (gmail.js:649:23)
    at Gmail.api.get.unread_inbox_emails (gmail.js:610:31)
    at Gmail.api.get.unread_emails (gmail.js:672:37)
    at <anonymous>:1:11

Getting this for all unread functions (gmail.get.unread_draft_emails(), gmail.get.unread_inbox_emails()). Calling inside

gmail.observe.on("load", () => { 
    const unreadEmails = gmail.get.unread_emails(); // Error here
    console.log(unreadEmails);
    ...
}
```

**Browser**: Brave Browser [Version 1.46.144 Chromium: 108.0.5359.128 (Official Build) unknown (64-bit)](https://brave.com/latest/)
**Extension Version**: 3
**gmail-js version**: ^1.1.1

becomingmountains avatar Apr 21 '23 16:04 becomingmountains

I believe many of the "complicated" or specialized calls in the gmail.get-namespace used for "old Gmail" is currently broken, because Gmail may no longer be using the protocol they used to determine this.

I believe the best fix for that would be to create new, corresponding implementations in the gmail.new.get-namespace.

josteink avatar May 25 '23 09:05 josteink

I went digging into this today. This breaks here:

    api.helper.get.navigation_count = function(i18nName) {
      const title = api.tools.i18n(i18nName);
      const dom = $("div[role=navigation]").find("[title*='" + title + "']");
      if (dom || dom.length > 0) {
        if (dom[0].title.indexOf(title) !== -1) {
          const value = parseInt(dom[0].attributes["aria-label"].value.replace(/[^0-9]/g, ""));
          if (!isNaN(value)) {
            return value;
          }
        }
      }
      return 0;
    };

This line no longer works: $("div[role=navigation]").find("[title*='" + title + "']")

I'm happy to write open a PR sometime this week to fix this. I don't know how or where to test this. Just looking at my Gmail inbox may not be enough.

stevenirby avatar Feb 07 '24 23:02 stevenirby

Sounds good. If you can come up with a PR which works for you, I would be willing to test it :)

josteink avatar Feb 08 '24 12:02 josteink

@josteink great! Thank you so much. I opened a PR here: https://github.com/KartikTalwar/gmail.js/pull/776

stevenirby avatar Feb 08 '24 15:02 stevenirby