When opening new tab by New Tab button, first opened tab's Tab.url is "about:blank", while should be "about:newtab"

RESOLVED INVALID

Status

RESOLVED INVALID
2 years ago
6 months ago

People

(Reporter: hmpro74, Unassigned)

Tracking

52 Branch
x86_64
Windows 7

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

2 years ago
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36

Steps to reproduce:

1. Open Firefox
2. Open a new tab by clicking New Tab button
3. In WebExtensions tabs.onCreated() callback function, the tabs.Tab parameter passed to callback, assume it is named as firefoxTab. Check the value of firefoxTab.url.


Actual results:

For the first opened tab, firefoxTab.url equals to "about:blank".


Expected results:

The value should be "about:newtab". Because from the second opened tab and after, the value for firefoxTab.url is "about:newtab". This value for the first opened tab is incompatible with the ones after.
(Reporter)

Comment 1

2 years ago
I check document.URL of first tab in console, its value is "about:newtab".
Version: 51 Branch → 52 Branch
(Reporter)

Updated

2 years ago
OS: Unspecified → Windows 7
Hardware: Unspecified → x86
(Reporter)

Updated

2 years ago
Hardware: x86 → x86_64

Updated

2 years ago
Component: Untriaged → WebExtensions: Untriaged
Product: Firefox → Toolkit
This is explained near the top of the page documenting the onCreated event:

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/Tabs/onCreated

Note that the tab's URL may not be given its final value at the time this event fired. In particular, Firefox opens a new tab with the URL "about:blank" before loading the new page into it. You can listen to tabs.onUpdated events to be notified when a URL is set.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → INVALID
(Reporter)

Comment 3

2 years ago
(In reply to Andrew Swan [:aswan] from comment #2)
> This is explained near the top of the page documenting the onCreated event:
> 
> https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/Tabs/onCreated
> 
> Note that the tab's URL may not be given its final value at the time this
> event fired. In particular, Firefox opens a new tab with the URL
> "about:blank" before loading the new page into it. You can listen to
> tabs.onUpdated events to be notified when a URL is set.

But why only the first tab opened by New Tab button behaves this way? This tab also triggers webNavigation.onCommitted event (I think it navigates from about:blank to about:newtab), while subsequent tabs opened by New Tab button, will not trigger.
(In reply to Martin Zhai from comment #3)
> But why only the first tab opened by New Tab button behaves this way? This
> tab also triggers webNavigation.onCommitted event (I think it navigates from
> about:blank to about:newtab), while subsequent tabs opened by New Tab
> button, will not trigger.

I don't know, I would guess that something that there is some initialization during the first load or something is cached, that causes subsequent loads to proceed more quickly so the final url happens to be available by the time onCreated is fired.  But why does it matter?  The documentation is pretty clear about how to handle this if you want to get the final url in a reliable way.

As for webNavigation, its not clear to me from the documentation what the expectation is, feel free to open a separate bug for that issue.
(Reporter)

Comment 5

2 years ago
(In reply to Andrew Swan [:aswan] from comment #4)
> (In reply to Martin Zhai from comment #3)
> > But why only the first tab opened by New Tab button behaves this way? This
> > tab also triggers webNavigation.onCommitted event (I think it navigates from
> > about:blank to about:newtab), while subsequent tabs opened by New Tab
> > button, will not trigger.
> 
> I don't know, I would guess that something that there is some initialization
> during the first load or something is cached, that causes subsequent loads
> to proceed more quickly so the final url happens to be available by the time
> onCreated is fired.  But why does it matter?  The documentation is pretty
> clear about how to handle this if you want to get the final url in a
> reliable way.
> 
> As for webNavigation, its not clear to me from the documentation what the
> expectation is, feel free to open a separate bug for that issue.

My intention is to diff tabs opened by click New Tab button, and ones opened by user click on link, on tab creation. My way is to check the tab.url property in callback of tabs.onCreated.

I found tabs opened by New Tab button, their urls always are "about:newtab"(except for the first one), while tabs opened by link, their urls are "about:blank".

I can't do this in tabs.onUpdated, because it may be fired more than once.

Updated

6 months ago
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.