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

(Question) Is there any way to perform a search from gmail.js? #800

Open
gonzalo-rodriguez opened this issue Nov 8, 2024 · 4 comments
Open

Comments

@gonzalo-rodriguez
Copy link

I am trying to create an extension using gmail.js (amazing project, by the way!) with a very simple aim: add a button anywhere in gmail (add_toolbar_button for instance is perfect) that performs a search for unread emails, so basically a search for is:unread.

I have been looking through the documentation, but haven't found a way to do so.

Is it possible to do it from gmail.js?

Thank you!

@josteink
Copy link
Collaborator

gmail.js does not have a API for actively searching the user's Gmail contents. It has an API for obtaining information/contents of specific emails given an ID.

In addition, the contents gmail.js can provide may be restricted to emails the user himself has visited (or which has been pre-cached due to the currently active view).

That said, the inbox is usually loaded, and contains information about this.

See the readme for available APIs, and if they don't work as expected, feel free to create a bug-report.

@gonzalo-rodriguez
Copy link
Author

Thank you for your answer @josteink!

However, just to clarify, I don't want to read the contents of the emails or anything like that, I just want to perform the search action (so, basically enter "is:unread" on the search box and then press enter).

I've been trying it myself with the available APIs, starting with gmail.dom.search_bar(), but so far I haven't been able to do it, gmail really likes to make its buttons hard to find and/or click!

Thanks again for your answer, though!

@josteink
Copy link
Collaborator

In that case, do you really need an API for it? Just observe the URL bar!

When I'm logged in and showing my inbox my URL is:

https://mail.google.com/mail/u/0/#inbox

When I navigate to the sent items folder, my URL is:

https://mail.google.com/mail/u/0/#sent

Surely if that's all you need to do, you can interact with the web-page directly to alter the URL hash?

@gonzalo-rodriguez
Copy link
Author

You're absolutely right, I was so focused on clicking buttons and stuff that just didn't think of that, and of course

https://mail.google.com/mail/u/0/#search/is%3Aunread

just does the trick :) Now it's just a matter of playing with URLs a bit.

Thanks a lot!

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

2 participants