Warren Benedetto
unread,Mar 12, 2011, 2:48:58 AM3/12/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Chromium-extensions
When a user switches to a new window, I want to show an overlay
concealing the content in the tabs they just switched away from. To do
this, I use chrome.windows.getLastFocused() to get the window on top.
I store that in a lastWindowTabs variable in the background script.
When the user switches to another window, I loop through
lastWindowTabs to show an overlay covering the content in all the tabs
they just switched away from. Then I reset lastWindowTabs to the new
window on top. In effect, lastWindowTabs always reflects the state of
the window that was focused *just before* the current one.
So far so good. That works.
Here's the problem:
If the user CLOSES the window they are on, focus switches back to the
other window. However, lastWindowTabs contains an array of tabs for
the window *which is now closed*. When I loop through that array, I
get this error:
chrome/RendererExtensionBindings:119Port error: Could not establish
connection. Receiving end does not exist.
Of course it couldn't establish the connection -- the window is
closed. The tabs don't exist anymore.
What I need to do is to check whether the tab still exists before
sending a message to it.
I tried using tabs.get(), thinking I'd get back undefined and could
use that. And I do get that, in the tabs.get() callback function. But
before that, I get "Error during tabs.get: No tab with id: 32.".
My question is: What can I do to check whether a tab exists? I want
some sort of tab.exists(tabId) that returns a boolean, but there is no
such function.
What are my other options?