I’m writing an extension that opens a tab when Chrome first runs, technically means placing code in the background page, which sounds simple enough, and works fine in Windows, and probably Linux as well, though I haven’t tested it.
The problem is with Mac, which doesn’t actually fully close Chrome when the user clicks the close button at the top left. To fully close Chrome you have to force quit it, which is something people generally do not do.
So this means I’ll need to rely on some other event to trigger code when the user first “opens” chrome. Does anyone have idea for which even that could be? I suppose I could add a listener to every tab’s create event and check the number of tabs, or something similar, but I’m looking for a light weight solution. Any ideas?
UPDATE: One idea us to use the chrome.windows.onCreated event and just check that there are no other windows open. Is that the best method, or can anyone think of something more efficient?
Use two events and a counter. Because window open/close are relatively rare, this should not be a problem:
onCreated, increase the counter, and validate the value.onRemoved, decrease the counter.