Q: chrome.tabs.create *hidden* tab?

6,538 views
Skip to first unread message

Bubba Bubbs

unread,
Sep 30, 2011, 3:07:54 PM9/30/11
to Chromium-extensions
Is it possible to create a *hidden* tab using chrome.tabs.create() ?

(In FireFox, I can do it by calling addTab(), and then setting the new
tab's 'hidden' property to true.)

-Bubba

Richard Wagener

unread,
Sep 30, 2011, 4:01:58 PM9/30/11
to Chromium-extensions
Bubba,

I think you can accomplish the same thing as a hidden tab by using the the background.html functionality.


Richard


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




--

Thanks,


Bubba Bubbs

unread,
Sep 30, 2011, 8:05:07 PM9/30/11
to Chromium-extensions
Without going into too much detail, let me explain a little bit what
I'm trying to do.

My web server will sometimes serve a page that will cause a series of
redirects. The first redirect is done by the page's JavaScript calling
window.location.replace(). The next page may then trigger a sequence
of HTTP 302 redirects. Eventually, we end up on the destination page.
So, for example, we may have this chain of events:

1. www.MyDomain.com/redirect.aspx -> window.location.replace( URL_2 );
2. URL_2 -> (302) URL_3
3. URL_3 -> (302) URL_4
4. URL_4 -> (302) www.MyDomain.com

There is a business reason for doing these redirects.
Now, in order to improve the user experience (so the user doesn't have
to watch these redirects happen), I would like to:

a) In Step 1 above, programmatically remove the path from the URL, and
just load www.MyDomain.com into the active tab.
b) Open a hidden tab (or an invisible Chrome window), and point it to
www.MyDomain.com/redirect.aspx, which should cause the above redirect
sequence happen in the "background" (invisible to the user).

(I would also use chrome.tabs.onUpdated() to detect when the redirect/
navigation is complete in the background tab, and close the tab.)

I haven't found a way to do that. I don't know if I can make a Chrome
tab hidden.
I also tried creating an invisible Chrome window:

chrome.windows.create( {url: "www.MyDomain.com/redirect.aspx" , width:
0, height: 0} );

but that didn't work. "width: 1, height: 1" didn't work, either.
There seems to be a low limit on "with" and "height", as the window,
although small, is always visible.

Thanks

Alvin Wong

unread,
Oct 2, 2011, 4:34:22 AM10/2/11
to Chromium-extensions
Why so complicated, I think that even AJAX can accomplish what you
want.
In theory, use AJAX to get your original page, then check the header
response (You can do that by JavaScript), and do anything you need. I
will not provice the actual script.
Another method is to use an iframe, but I don't know how you would
detect if the redirect sequence is completed.
I can't understand why you would need a hidden tab or window.
(You could not set a window size to 0 when the window has a border,
that is a limitation in Windows.)
By the way do you need to process JavaScript redirect, or just header
3xx response?

On 10月1日, 上午8時05分, Bubba Bubbs <6u66a6u...@gmail.com> wrote:
> Without going into too much detail, let me explain a little bit what
> I'm trying to do.
>
> My web server will sometimes serve a page that will cause a series of
> redirects. The first redirect is done by the page's JavaScript calling
> window.location.replace(). The next page may then trigger a sequence
> of HTTP 302 redirects. Eventually, we end up on the destination page.
> So, for example, we may have this chain of events:
>
> 1.www.MyDomain.com/redirect.aspx-> window.location.replace( URL_2 );
> 2. URL_2  -> (302)  URL_3
> 3. URL_3  -> (302)  URL_4
> 4. URL_4  -> (302)www.MyDomain.com
>
> There is a business reason for doing these redirects.
> Now, in order to improve the user experience (so the user doesn't have
> to watch these redirects happen), I would like to:
>
> a) In Step 1 above, programmatically remove the path from the URL, and
> just loadwww.MyDomain.cominto the active tab.
> b) Open a hidden tab (or an invisible Chrome window), and point it towww.MyDomain.com/redirect.aspx, which should cause the above redirect

Bubba Bubbs

unread,
Oct 3, 2011, 7:25:42 PM10/3/11
to Chromium-extensions
Alvin:

What you are proposing actually seems more complicated - AJAX, then
JavaScript to parse the header of the XHResponse. I would have to do
that for the "downstream" pages in the redirect sequence, too, because
some of them could be 302-redirects, but some could be using
window.location.replace().

What I was trying to do is simply load the first URL to a (background)
tab, and then the tab/browser handles the rest (plus, some fairly
simple aux code to close the background tab once the redirects are
finished.)

Bubba
> > just loadwww.MyDomain.comintothe active tab.

Mihai Parparita

unread,
Oct 3, 2011, 7:30:14 PM10/3/11
to Bubba Bubbs, Chromium-extensions
Have you considered opening the tab to www.MyDomain.com, and in your background page creating an iframe with src www.MyDomain.com/redirect.aspx? The background page will request it as usual (and follow redirects). You don't even need to have a final redirect back to www.MyDomain.com, you could just use window.postMessage to inform the parent background page that the redirects are done and the iframe can be removed.

Mihai

Bubba Bubbs

unread,
Oct 17, 2011, 12:14:53 PM10/17/11
to Chromium-extensions
Thanks Mihai and Richard. I am using the approach you suggested - open
<iframe>s within background.html, and then close them when the
navigation completes.
Works great!

On Oct 3, 5:30 pm, Mihai Parparita <mih...@chromium.org> wrote:
> Have you considered opening the tab towww.MyDomain.com, and in your
> background page creating an iframe with srcwww.MyDomain.com/redirect.aspx?
> The background page will request it as usual (and follow redirects). You
> don't even need to have a final redirect back towww.MyDomain.com, you could
> > > > just loadwww.MyDomain.comintotheactive tab.
> > > > b) Open a hidden tab (or an invisible Chrome window), and point it
> > towww.MyDomain.com/redirect.aspx, which should cause the above redirect
> > > > sequence happen in the "background" (invisible to the user).
>
> > > > (I would also use chrome.tabs.onUpdated() to detect when the redirect/
> > > > navigation is complete in the background tab, and close the tab.)
>
> > > > I haven't found a way to do that. I don't know if I can make a Chrome
> > > > tab hidden.
> > > > I also tried creating an invisible Chrome window:
>
> > > > chrome.windows.create( {url: "www.MyDomain.com/redirect.aspx" , width:
> > > > 0, height: 0} );
>
> > > > but that didn't work.  "width: 1, height: 1" didn't work, either.
> > > > There seems to be a low limit on "with" and "height", as the window,
> > > > although small, is always visible.
>
> > > > Thanks
>
> > > > On Sep 30, 1:07 pm, Bubba Bubbs <6u66a6u...@gmail.com> wrote:
>
> > > > > Is it possible to create a *hidden* tab using chrome.tabs.create() ?
>
> > > > > (In FireFox, I can do it by calling addTab(), and then setting the
> > new
> > > > > tab's 'hidden' property to true.)
>
> > > > > -Bubba
>
> > --
> > 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.
Reply all
Reply to author
Forward
0 new messages