Keeping per-tab state with the browser action

279 views
Skip to first unread message

Matias Pelenur

unread,
Feb 20, 2010, 2:48:56 PM2/20/10
to Chromium-extensions
Browser action buttons can be modified by tab, which is great; you can
change the icon, badge, and tooltip on a tab-by-tab basis.

The problem comes when browser action clicks need different actions by
tab, too. I think this is a likely use case, given that you can
already set per-tab state. For example, you may grey-out the button
for some tabs; in those tabs, clicking it may need to do something
different than when the button is not greyed out.

Since Chrome is already keeping per-tab state for the browser action,
could we modify the API to either attach some state per tab
(chrome.browserAction.setData({data: {foo: bar}}, tabId: tabId})), or
alternatively to at least read the state of the browser action for a
tab? That is, have chrome.browserAction.{getBadgeText,getIcon,getTitle}
(tabId). Even just having those methods would avoid having to keep tab
state separately in the background page.

An alternative that may be more general is to add an API to
chrome.tabs for setting arbitrary tab data that lives only until a tab
changes URL or is removed. Why not just do this yourself in the
background page? It's bug-prone (you have to keep track of tabRemoved
events; tabUpdated gets called twice (loading and complete), for
example), and seems general enough to be added to the API.

Thoughts?

Thanks,
matias

Alex

unread,
Feb 26, 2010, 11:18:46 AM2/26/10
to Chromium-extensions
This sounds good to me. What do Chrome developers think?

Pauan

unread,
Mar 2, 2010, 4:26:25 AM3/2/10
to Chromium-extensions
Two things:

1) Page actions are supposed to be used for actions that occur on a
tab-by-tab basis. Browser actions are supposed to be used for more
general things that affect the entire browser.

2) Assuming you're right that browser action state is saved per tab,
this sounds reasonable to me. I think something like this would
suffice:

chrome.browserAction.getInfo(tab, function (object) {});

"tab" is a tab, or defaults to the current-selected tab. "object" is
details about the browser action, like icon, text, etc.

The proposal to store state in the tab object itself also sounds okay.
That could be a function call, or an object attached directly to the
tab, like this:

tab.data.isDisabled = true;

Erik Kay

unread,
Mar 8, 2010, 12:02:50 PM3/8/10
to Matias Pelenur, Chromium-extensions
This seems like a reasonable request.  I think our initial take was that this is straightforward enough for folks to implement themselves (it's just a trivial map after all), but I think your point about avoiding common bugs and simplifying common patterns is a reasonable one.

Between your two suggestions, I think I prefer the more general one (setting arbitrary per-tab data that's cleared when the URL changes), that way it could be used in any API that's receives a tab in its callback.

Could you please file a feature request for this?  crbug.com/new

Erik



--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Matias Pelenur

unread,
Mar 8, 2010, 12:09:49 PM3/8/10
to Erik Kay, Chromium-extensions
Thanks, Erik. Created bug crbug.com/37671.

-matias
Reply all
Reply to author
Forward
0 new messages