Tab.lastAccessed Not Reliably Updating

310 views
Skip to first unread message

Aaron Singer

unread,
Apr 4, 2024, 4:37:28 AM4/4/24
to Chromium Extensions
Can anyone verify whether the relatively new tabs API Tab.lastAccessed is reliably returning the time of last access? I'm using it to try to get the last accessed  non-extension tab but it is not reliably updating even after giving the tab focus, refreshing or scrolling.  

As an aside, it would be nice if the docs can define what "last accessed" means, ie: what form of interaction is considered an access. 

Oliver Dunk

unread,
Apr 4, 2024, 5:00:11 AM4/4/24
to Aaron Singer, Chromium Extensions
Hi Aaron,

This should be the last time the focus state of the tab changed to active. It doesn't continuously update while the tab is focused, but should remember the timestamp from when it was activated.

On my side, that seems to be working. Are you seeing something different? Do you have steps to reproduce you could share?

Appreciate the comment on the documentation, I can take a look at updating that.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


On Thu, Apr 4, 2024 at 9:37 AM Aaron Singer <singe...@gmail.com> wrote:
Can anyone verify whether the relatively new tabs API Tab.lastAccessed is reliably returning the time of last access? I'm using it to try to get the last accessed  non-extension tab but it is not reliably updating even after giving the tab focus, refreshing or scrolling.  

As an aside, it would be nice if the docs can define what "last accessed" means, ie: what form of interaction is considered an access. 

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/9d662065-7053-41c9-8aad-1f0f60697aa0n%40chromium.org.

Aaron Singer

unread,
Apr 4, 2024, 5:50:15 AM4/4/24
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Aaron Singer
Hi Oliver, thanks for explaining that, and apologies to the group for the multiple posts. They didn't go up over a 24 hour period so I messaged Google support and they all went up near simultaneously. 

"The last time the focus state of the tab changed to active" explains it well, that actually solves why the timestamps weren't updating. I was switching between windows, refreshing, and scrolling, none of which changes the state of the foremost tabs from nonactive to active. I tested when switching tabs within a window, and the lastAccessed property updates appropriately. 

Can you update the definition on the docs? Knowing that definition of accessed would have saved me a lot of trouble. "lastFocused" would probably be a better name, honestly. 

It would also be helpful if there was an out-of-the-box way to get the lastFocused non-extension window. Window.getLastFocused doesn't help because it can return the extension window.

Oliver Dunk

unread,
Apr 4, 2024, 5:55:43 AM4/4/24
to Aaron Singer, Chromium Extensions
No worries about the multiple posts! We have a moderation queue so Patrick or I needed to approve them - I would've picked one to accept and declined the others but I missed they were duplicates at first :)

Glad the explanation helped! I've submitted an update to our documentation here and just need to get it reviewed: https://chromium-review.googlesource.com/c/chromium/src/+/5419402. On the naming, that's fair - given this is also supported in Firefox I don't expect we will change it short term but appreciate the confusion.

Getting the last-focused non-extension window is interesting. I wonder if just "getAllTabsSortedByLastAccessed" would work (admittedly, you can already do this quite easily with sort).
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB

Aaron Singer

unread,
Apr 4, 2024, 6:31:58 AM4/4/24
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Aaron Singer
That sounds sort of like what Window.getLastFocused does,  but for tabs. getAllTabsSortedByLastAccessed would not be as helpful though, because switching between windows doesn't change the focus state of the foremost tab in each window. 

Adding a WindowType that essentially means "not the extension" would probably do it. Or adding a lastAccessed state to each Window object and then the programmer can exclude their extension window programatically. 

Thanks for your attention!

Reply all
Reply to author
Forward
0 new messages