chrome.windows.getCurrent and chrome.windows.create from a background extension

785 views
Skip to first unread message

Julien Genestoux

unread,
Apr 14, 2011, 11:05:25 AM4/14/11
to Chromium-extensions
Hello,

We built an extension and this extension needs to open tabs from a
background page.

We use chrome.tabs.create which works great... except when there are
no window open, an error is raised.

We tried then to use chrome.windows.getCurrent to see if there is any
window open, but that raises an error too if none is opened

So we tried chrome.windows.getAll and if we get an empty array, then,
we try to chrome.windows.create in which we can open the tab. The
problem is that it crashes Chrome all together!

So, my question is simple : how to open a tab when there is no window
open?

Arne Roomann-Kurrik

unread,
Apr 14, 2011, 2:21:36 PM4/14/11
to Julien Genestoux, Chromium-extensions
What's the error you get?  Are you running this from one of the new background apps: http://blog.chromium.org/2011/02/amping-up-chromes-background-feature.html ?

~Arne



--
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.


Adam

unread,
Apr 15, 2011, 11:57:03 AM4/15/11
to Chromium-extensions
Minor note, you don't need to check for an empty array to see if a
window exists.

You can use test chrome.windows.WINDOW_ID_NONE instead of calling
chrome.windows.getAll


Do you know if the chrome.windows.getAll crashes chrome or if
chrome.windows.create causes the crash?

-Adam

On Apr 14, 11:05 am, Julien Genestoux <julien.genest...@gmail.com>
wrote:

Julien Genestoux

unread,
May 6, 2011, 8:13:45 AM5/6/11
to Adam, Chromium-extensions
Arne, yes, running from a backgound page. Sometimes, we need to open an actual tab, even if no window is currently open.

Adam, chrome.windows.WINDOW_ID_NONE is _always_ -1. Not sure how to use that. any hint?

Thanks

Adam

unread,
May 6, 2011, 11:22:29 AM5/6/11
to Chromium-extensions
chrome.windows.WINDOW_ID_NONE allows you to test for the existence of
a chrome window. If it is 0, then it means no window is open.

This is to account for the new "background" permission.

Perhaps you could open an iframe in the background page? They can
communicate through message passing just like a content script running
in a tab. You just have to make sure and set all_frames: true

-Adam

On May 6, 8:13 am, Julien Genestoux <julien.genest...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages