window.setTimeout(gBrowser.addTab, time, URL) causes an error message "this.mCurrentTab is undefined"

RESOLVED INVALID

Status

()

Firefox
Tabbed Browser
--
major
RESOLVED INVALID
7 years ago
7 years ago

People

(Reporter: vsemozhetbyt, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

7 years ago
User-Agent:       Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0
Build Identifier: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0

"Error: this.mCurrentTab is undefined Source: chrome://browser/content/tabbrowser.xml String: 1188"



Reproducible: Always

Steps to Reproduce:
For Example, try this in an extension or other test code: 

window.setTimeout(gBrowser.addTab, 1000, "http://www.google.com/");

Actual Results:  
Code with this call is broken.

Expected Results:  
gBrowser should open the URL in a tab after the time delay.
> For Example, try this in an extension or other test code: 
> 
> window.setTimeout(gBrowser.addTab, 1000, "http://www.google.com/");

This code is just broken. Try gBrowser.addTab.bind(gBrowser) instead of gBrowser.addTab.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → INVALID
(Reporter)

Comment 2

7 years ago
(In reply to comment #1)
> This code is just broken. Try gBrowser.addTab.bind(gBrowser) instead of
> gBrowser.addTab.

Does you mean:

window.setTimeout(gBrowser.addTab.bind(gBrowser), 1000, "http://www.google.com/");

? This code open an empty tab with correct URL but without any content at all.
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
(In reply to comment #2)
> (In reply to comment #1)
> > This code is just broken. Try gBrowser.addTab.bind(gBrowser) instead of
> > gBrowser.addTab.
> 
> Does you mean:
> 
> window.setTimeout(gBrowser.addTab.bind(gBrowser), 1000,
> "http://www.google.com/");
> 
> ? This code open an empty tab with correct URL but without any content at
> all.

The problem here is that setTimout passes a second argument to addTab. This is bug 394769. I also filed bug 662155 on the fact that addTab fails silently here rather than reporting the error.

As a workaround, you may use this:

setTimout(function () {
  gBrowser.addTab("http://google.com");
}, 1000);
Status: UNCONFIRMED → RESOLVED
Last Resolved: 7 years ago7 years ago
Resolution: --- → INVALID
(Reporter)

Comment 4

7 years ago
(In reply to comment #3)
> As a workaround, you may use this:
> 
> setTimout(function () {
>   gBrowser.addTab("http://google.com");
> }, 1000);

It works. Thank you very much for your time and explanation.
You need to log in before you can comment on or make changes to this bug.