How do you use the chrome.tabs module to create a new tab? And a question about alert boxes.

3,004 views
Skip to first unread message

fterh

unread,
Mar 22, 2010, 5:36:54 AM3/22/10
to Chromium-extensions
Hi,

How do you use the chrome.tabs module to create a new tab? I have
already declared the "tabs" permission in manifest.json, and this is
how my popup.html looks like.

<script type="text/javascript">
function createTab() {
chrome.tabs.create();
}
</script>

<body>
<a onclick="createTab();">Click me</a>
</body>

But it doesn't work. I tried looking at samples in
http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/tabs/
but they're too complicated and I don't have the time to figure out
the essential code for tab creation.

Cheers
Fabian

Mohamed Mansour

unread,
Mar 23, 2010, 8:23:07 AM3/23/10
to fterh, Chromium-extensions
You are not specifying any parameters in that call:

Says, you have to specify a "createProperties", so do this:
chrome.tabs.create({url: 'http://google.ca'});

-
Mohamed Mansour
m...@chromium.org



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


fterh

unread,
Mar 23, 2010, 8:51:37 AM3/23/10
to Chromium-extensions
Thanks, though I figured that out already.

Just curious, here (http://code.google.com/chrome/extensions/
tabs.html#method-create) it states that all four windowId, index, url
& selected are optional. So how come it doesn't work when I don't
specify one of them?

Ken Liu

unread,
Mar 23, 2010, 8:55:13 AM3/23/10
to fterh, Chromium-extensions
The first argument to create() is required. You can pass null or an
empty object, though.

Ken

Sam Kerner

unread,
Mar 23, 2010, 9:36:37 AM3/23/10
to fterh, Chromium-extensions
On Tue, Mar 23, 2010 at 8:51 AM, fterh <fabia...@gmail.com> wrote:

Optional arguments can be set to null or undefined. If they are, a
default value is used. Issue 29215 tracks work allowing optional
arguments to be omitted.

Sam

fterh

unread,
Mar 23, 2010, 9:53:59 AM3/23/10
to Chromium-extensions
What do you mean issue 29215? Do I have to like, update Chrome or
anything?

On Mar 23, 9:36 pm, Sam Kerner <sker...@google.com> wrote:


> On Tue, Mar 23, 2010 at 8:51 AM, fterh <fabiani...@gmail.com> wrote:
> > Thanks, though I figured that out already.
>
> > Just curious, here (http://code.google.com/chrome/extensions/
> > tabs.html#method-create) it states that all four windowId, index, url
> > & selected are optional. So how come it doesn't work when I don't
> > specify one of them?
>
>    Optional arguments can be set to null or undefined.  If they are, a
> default value is used.  Issue 29215 tracks work allowing optional
> arguments to be omitted.
>
> Sam
>
>
>
>
>
> > --
> > You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.

> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to chromium-extensions+unsubscr...@chromium.org.

Daniel Wagner-Hall

unread,
Mar 23, 2010, 10:12:15 AM3/23/10
to fterh, Chromium-extensions
If you look at http://crbug.com/29215 you can track the progress of
work to allow optional parameters. It hasn't been fixed yet.

> To post to this group, send email to chromium-...@chromium.org.
> To unsubscribe from this group, send email to chromium-extens...@chromium.org.

Sam Kerner

unread,
Mar 23, 2010, 10:13:25 AM3/23/10
to fterh, Chromium-extensions
On Tue, Mar 23, 2010 at 9:53 AM, fterh <fabia...@gmail.com> wrote:
> What do you mean issue 29215? Do I have to like, update Chrome or
> anything?

We have an issues tracker to record work to be done. You can see
issue 29215 here:

http://code.google.com/p/chromium/issues/detail?id=29215

The open issue means we know about the problem, and plan to fix it,
but it has not yet been fixed.

Sam

> To post to this group, send email to chromium-...@chromium.org.
> To unsubscribe from this group, send email to chromium-extens...@chromium.org.

fterh

unread,
Mar 24, 2010, 7:25:00 AM3/24/10
to Chromium-extensions
How do you create a tab without passing any arguments?

I tried:

chrome.tabs.create(null);
chrome.tabs.create({null});
chrome.tabs.create({url:null});

but none of them worked. The last one crashed the extension though.

On Mar 23, 9:36 pm, Sam Kerner <sker...@google.com> wrote:

> On Tue, Mar 23, 2010 at 8:51 AM, fterh <fabiani...@gmail.com> wrote:
> > Thanks, though I figured that out already.
>
> > Just curious, here (http://code.google.com/chrome/extensions/
> > tabs.html#method-create) it states that all four windowId, index, url
> > & selected are optional. So how come it doesn't work when I don't
> > specify one of them?
>
>    Optional arguments can be set to null or undefined.  If they are, a
> default value is used.  Issue 29215 tracks work allowing optional
> arguments to be omitted.
>
> Sam
>
>
>
>
>
> > --
> > You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.

> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to chromium-extensions+unsubscr...@chromium.org.

Sam Kerner

unread,
Mar 24, 2010, 10:46:49 AM3/24/10
to fterh, Chromium-extensions
On Wed, Mar 24, 2010 at 7:25 AM, fterh <fabia...@gmail.com> wrote:
> How do you create a tab without passing any arguments?

The docs* give the following function for creating a tab:

chrome.tabs.create(object createProperties, function callback)

The first argument is not optional, so you should not call the
function without arguments. All properties of createProperties are
optional, so chrome.tabs.create({}, function(){}); should work.

Stepping back, why do you need to call chrome.tabs.create() without
arguments?

*: http://code.google.com/chrome/extensions/tabs.html

>
> I tried:
>
> chrome.tabs.create(null);
> chrome.tabs.create({null});
> chrome.tabs.create({url:null});
>
> but none of them worked. The last one crashed the extension though.

That last one should error out without crashing. Would you mind
filing a bug at http://crbug.com/?

Sam

>
> On Mar 23, 9:36 pm, Sam Kerner <sker...@google.com> wrote:
>> On Tue, Mar 23, 2010 at 8:51 AM, fterh <fabiani...@gmail.com> wrote:
>> > Thanks, though I figured that out already.
>>
>> > Just curious, here (http://code.google.com/chrome/extensions/
>> > tabs.html#method-create) it states that all four windowId, index, url
>> > & selected are optional. So how come it doesn't work when I don't
>> > specify one of them?
>>
>>    Optional arguments can be set to null or undefined.  If they are, a
>> default value is used.  Issue 29215 tracks work allowing optional
>> arguments to be omitted.
>>
>> Sam
>>
>>
>>
>>
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
>> > To post to this group, send email to chromium-extensi...@chromium.org.
>> > To unsubscribe from this group, send email to chromium-extensions+unsubscr...@chromium.org.
>> > For more options, visit this group athttp://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
>
> --
> 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.

Finnur Thorarinsson

unread,
Mar 24, 2010, 12:27:40 PM3/24/10
to Sam Kerner, fterh, Chromium-extensions
> That last one should error out without crashing.  Would you mind
> filing a bug at http://crbug.com/?

I don't think we consider this a bug.

We try to be extra careful in validating the parameters passed in to avoid creating security issues in the extension system. So, while you can leave the URL parameter out (since it is optional) -- but if you specify it, it can not be NULL. 

We have a macro (EXTENSION_FUNCTION_VALIDATE) whose purpose is to validate the parameters and crash the extension when it sends garbage parameters and that's what is happening here.

I second what Sam said. What are you trying to do? The create function defaults to the New Tab page if you don't specify a url. And if you don't want to load a url and you don't want the new tab page then at a minimum you need to specify url:"about:blank" to open a blank tab. 

Ken Liu

unread,
Mar 24, 2010, 3:41:58 PM3/24/10
to Finnur Thorarinsson, Sam Kerner, fterh, Chromium-extensions
Is it really necessary to crash the extension in case of bad
parameters? Wouldn't it be better to simply log an error message or
throw an Exception?

Antony Sargent

unread,
Mar 24, 2010, 4:00:02 PM3/24/10
to Ken Liu, Finnur Thorarinsson, Sam Kerner, fterh, Chromium-extensions
In many cases we do just return an error via chrome.extension.lastError (http://code.google.com/chrome/extensions/extension.html#property-lastError). But in one or two places the arguments we get are nonsensical enough or we're far enough through processing an API call when an error occurs that crashing the extension is the safest way to handle things. I think we could probably do a little better in some cases though. 

PhistucK

unread,
Mar 26, 2010, 8:26:38 AM3/26/10
to Antony Sargent, Ken Liu, Finnur Thorarinsson, Sam Kerner, fterh, Chromium-extensions
Well, I really believe that chrome.tabs.create({url:null}) is not a proper crashing reason.

☆PhistucK

Antony Sargent

unread,
Mar 26, 2010, 11:23:57 AM3/26/10
to PhistucK, Ken Liu, Finnur Thorarinsson, Sam Kerner, fterh, Chromium-extensions
Agreed. I just created a bug for this:

Erik Kay

unread,
Mar 26, 2010, 2:10:13 PM3/26/10
to Finnur Thorarinsson, Sam Kerner, fterh, Chromium-extensions
On Wed, Mar 24, 2010 at 9:27 AM, Finnur Thorarinsson <fin...@chromium.org> wrote:
> That last one should error out without crashing.  Would you mind
> filing a bug at http://crbug.com/?

I don't think we consider this a bug.

We try to be extra careful in validating the parameters passed in to avoid creating security issues in the extension system. So, while you can leave the URL parameter out (since it is optional) -- but if you specify it, it can not be NULL. 

We have a macro (EXTENSION_FUNCTION_VALIDATE) whose purpose is to validate the parameters and crash the extension when it sends garbage parameters and that's what is happening here.

Just to be clear, this isn't a reason for us to crash.  This crash behavior is meant to be a last line of defense against a compromised renderer, and it shouldn't be possible for extension authors to trigger it under normal conditions.  If they are, then it's the fault of our renderer-side JS validation code, not the extension author.

If you ever see a crash from using the API, even incorrectly, please file a bug so that we're aware of the issue.  This isn't desired behavior in any case.

Erik

karl

unread,
Mar 27, 2010, 3:48:11 PM3/27/10
to Chromium-extensions
Hi Erik,

We're getting a bunch off reviews saying our extension is crashing at
random, but we cannot recreate the crash ourselves.
What should we tell our users to send us so we can get information
about the cause of the crash?


On Mar 27, 7:10 am, Erik Kay <erik...@chromium.org> wrote:
> On Wed, Mar 24, 2010 at 9:27 AM, Finnur Thorarinsson <fin...@chromium.org>wrote:
>
> > > That last one should error out without crashing.  Would you mind

> > > filing a bug athttp://crbug.com/?


>
> > I don't think we consider this a bug.
>
> > We try to be extra careful in validating the parameters passed in to avoid
> > creating security issues in the extension system. So, while you can leave
> > the URL parameter out (since it is optional) -- but if you specify it, it
> > can not be NULL.
>
> > We have a macro (EXTENSION_FUNCTION_VALIDATE) whose purpose is to validate
> > the parameters and crash the extension when it sends garbage parameters and
> > that's what is happening here.
>
> Just to be clear, this isn't a reason for us to crash.  This crash behavior
> is meant to be a last line of defense against a compromised renderer, and it
> shouldn't be possible for extension authors to trigger it under normal
> conditions.  If they are, then it's the fault of our renderer-side JS
> validation code, not the extension author.
>
> If you ever see a crash from using the API, even incorrectly, please file a
> bug so that we're aware of the issue.  This isn't desired behavior in any
> case.
>
> Erik
>
>
>
> > I second what Sam said. What are you trying to do? The create function
> > defaults to the New Tab page if you don't specify a url. And if you don't
> > want to load a url and you don't want the new tab page then at a minimum you
> > need to specify url:"about:blank" to open a blank tab.
>

> > On Wed, Mar 24, 2010 at 07:46, Sam Kerner <sker...@google.com> wrote:


>
> >> On Wed, Mar 24, 2010 at 7:25 AM, fterh <fabiani...@gmail.com> wrote:
> >> > How do you create a tab without passing any arguments?
>
> >>    The docs* give the following function for creating a tab:
>
> >> chrome.tabs.create(object createProperties, function callback)
>
> >>   The first argument is not optional, so you should not call the
> >> function without arguments.  All properties of createProperties are
> >> optional, so chrome.tabs.create({}, function(){}); should work.
>
> >>   Stepping back, why do you need to call chrome.tabs.create() without
> >> arguments?
>
> >> *:http://code.google.com/chrome/extensions/tabs.html
>
> >> > I tried:
>
> >> > chrome.tabs.create(null);
> >> > chrome.tabs.create({null});
> >> > chrome.tabs.create({url:null});
>
> >> > but none of them worked. The last one crashed the extension though.
>
> >>    That last one should error out without crashing.  Would you mind

> >> filing a bug athttp://crbug.com/?


>
> >> Sam
>
> >> > On Mar 23, 9:36 pm, Sam Kerner <sker...@google.com> wrote:
> >> >> On Tue, Mar 23, 2010 at 8:51 AM, fterh <fabiani...@gmail.com> wrote:
> >> >> > Thanks, though I figured that out already.
>
> >> >> > Just curious, here (http://code.google.com/chrome/extensions/
> >> >> > tabs.html#method-create) it states that all four windowId, index, url
> >> >> > & selected are optional. So how come it doesn't work when I don't
> >> >> > specify one of them?
>
> >> >>    Optional arguments can be set to null or undefined.  If they are, a
> >> >> default value is used.  Issue 29215 tracks work allowing optional
> >> >> arguments to be omitted.
>
> >> >> Sam
>
> >> >> > --
> >> >> > You received this message because you are subscribed to the Google
> >> Groups "Chromium-extensions" group.
> >> >> > To post to this group, send email to
> >> chromium-extensi...@chromium.org.
> >> >> > To unsubscribe from this group, send email to

> >> chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>


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

> >> chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>


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

> >> To post to this group, send email to chromium-extensi...@chromium.org.
> >> To unsubscribe from this group, send email to

> >> chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>


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

> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to

> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>

Antony Sargent

unread,
Mar 29, 2010, 1:33:27 PM3/29/10
to karl, Chromium-extensions
Aaron recently fixed a bug that was causing crashes for some extensions - you might have them try with the latest dev channel build of chrome and see if that fixes the problem. 

To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

karl

unread,
Mar 29, 2010, 4:07:42 PM3/29/10
to Chromium-extensions
Which bug was this? It would be nice to be able to point disgruntled
users to it and say "not our fault"* ;-)

*Actually I found a bug in the sqlite database handler I'm using that
may have also been the cause of the crashes. I'm currently trying to
recreate it and if so will create a proper bug report for the chromium
team.

> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>


>
> > > >> .
> > > >> >> > For more options, visit this group athttp://
> > > >> groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
>
> > > >> > --
> > > >> > You received this message because you are subscribed to the Google
> > > >> Groups "Chromium-extensions" group.
> > > >> > To post to this group, send email to
> > chromium-extensi...@chromium.org.
> > > >> > To unsubscribe from this group, send email to
> > > >> chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>

> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>


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

> > > >> To unsubscribe from this group, send email to
> > > >> chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>

> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>


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

> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>

Antony Sargent

unread,
Mar 29, 2010, 6:34:14 PM3/29/10
to karl, Chromium-extensions
http://code.google.com/p/chromium/issues/detail?id=38857

To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
Reply all
Reply to author
Forward
0 new messages