How to get the opener tab id?

852 views
Skip to first unread message

pdwiki

unread,
Jul 1, 2016, 9:49:07 PM7/1/16
to Chromium-dev
Hello,

Is there a way to track which one is the parent tab of the newly opened tab? Suppose I am in website A and click on a link and open up website B in another tab - is there a way to get the tab id of website A? I see a setShouldSetOpener function but am not sure if that is the right one to use. Can someone help me out with this or point me to the right resource?

Thanks in advance.

pdwiki

unread,
Jul 2, 2016, 3:22:12 PM7/2/16
to Chromium-dev
Any idea anyone?

Daniel Cheng

unread,
Jul 3, 2016, 8:28:29 PM7/3/16
to praba...@gmail.com, Chromium-dev
I'm not sure what you mean by tab ID. If you're referring to the extension API, look at the chrome.tabs API: there's a chrome.tabs.get() which retrieves information about a tab. One of the things it returns is the openerTabId.

If you're referring to pure web APIs, then an opened window can get a reference to the window that opened it with the window.opener property: https://developer.mozilla.org/en-US/docs/Web/API/Window/opener. This assumes the window wasn't opened with something like noopener.

Daniel

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

pdwiki

unread,
Jul 3, 2016, 9:46:54 PM7/3/16
to Chromium-dev, praba...@gmail.com
Hi Daniel,

Thanks for your reply. I will try to be more specific as to what I am trying achieve. I am modifying the Chromium code and not writing an extension.

This is the code I have:

NavigationController* tab = content::Source<NavigationController>(source).ptr();
int referrer_tab = -1 ;
if(tab->GetWebContents()->HasOpener()) {
    WebContents* opener = browser_->tab_strip_model()->GetOpenerOfWebContentsAt(tabindex) ;
    referrer_tab = browser_->tab_strip_model()->GetIndexOfWebContents(opener) ;
}

This code used to work fine in Chromium 32.x. In Chromium 32.x, if a tab was opened from another tab then I was able to get the tab id of the opener tab using the above code.  When I updated to Chromium 51.x, this code always gives back tab->GetWebContents()->HasOpener() as false.

I am trying to figure out how to get the opener tab id in the above manner.

Thanks in advance for your help.

Daniel Cheng

unread,
Jul 3, 2016, 9:55:04 PM7/3/16
to praba...@gmail.com, Chromium-dev
noopener for window.open was implemented in M49: https://chromium.googlesource.com/chromium/src.git/+/a06be427005b97ab47c16e2bd4b6fd6b254c24cc

$ git find-releases a06be427005b97ab47c16e2bd4b6fd6b254c24cc
commit a06be427005b97ab47c16e2bd4b6fd6b254c24cc was:
  initially in 49.0.2569.0

Are you sure noopener isn't in the 3rd argument to window.open()? Otherwise, this sounds like it could be a bug: if you could file a bug at https://crbug.com/new with a test case, that'd be helpful to figure out what's going wrong.

Daniel

Reply all
Reply to author
Forward
0 new messages