对于webExtension我试图通过发送xmlhttprequest来检查gmail收件箱:
https://mail.google.com/mail/u/0/feed/atom
https://mail.google.com/mail/u/1/feed/atom
https://mail.google.com/mail/u/2/feed/atom
...等等每个帐户。我想为所有当前登录的帐户执行此操作,但我不知道如何找到该号码。
当然,有一种愚蠢的方式,因为我只是继续递增u /#/直到我循环回到/ u / 0 /,并在那里进行检查。
但这很慢,因为我必须等待异步返回,跳得更好。
答案 0 :(得分:0)
不确定gmail,但您可以使用browser.cookies.getAll来阅读" mail.google.com"的所有用户Cookie。 (或accounts.google.com或类似)。
这假设您知道您要查找的cookie的名称,以便您可以推断用户登录的帐户数。
另外,请确保将cookies
权限添加到manifest.json
browser.cookies.getAll({ domain: 'mail.google.com' })
.then(cookies => {
// do something with the cookies
});
如果您可以假设每个gmail收件箱都在某个标签中打开,那么您可以只查询所有当前标签:
browser.tabs.query({ url: "https://mail.google.com/mail/u/*" })
.then(tabs => {
tabs.forEach(tab => {
// do an XHR request to tab.url or just extract the inbox ID for later use
});
})