Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
becomingmountains opened this issue Apr 21, 2023 · 4 comments

Comments

@becomingmountains
Copy link

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
@josteink
Copy link
Collaborator

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.

@stevenirby
Copy link

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.

@josteink
Copy link
Collaborator

josteink commented Feb 8, 2024

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

@stevenirby
Copy link

@josteink great! Thank you so much. I opened a PR here: #776

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants