Project: chromium Issues People Development process History Sign in
New issue
Advanced search Search tips
Issue 162049 window.open opens new window when it should open a tab
Starred by 19 users Reported by souders@google.com, Nov 20, 2012 Back to list
Status: Fixed
Owner: ----
Closed: Aug 2015
Cc: nyerramilli@chromium.org
Components:
OS: All
Pri: 2
Type: Compat


Sign in to add a comment
Chrome Version       : 23.0.1271.64
OS Version: OS X 10.8.2
URLs (if applicable) :
Other browsers tested:
  Add OK or FAIL after other browsers where you have tested this issue:
     Safari 5:
  Firefox 4.x:
     IE 7/8/9:

What steps will reproduce the problem?
1. Call window.open 2 or more times. For example:
    window.open("http://www.google.com/");
    window.open("http://www.yahoo.com/");
Here's a test page: http://stevesouders.com/tests/window-open.php

What is the expected result?
All the URLs are open in a new tab. 

What happens instead of that?
The first URL is opened in a new tab. All the remaining URLs are opened in a new window. We could debate whether all the URLs are opened in a new tab vs a new window. Most browsers have a setting to control this and the test works as expected. But it's really weird that Chrome mixes the behavior - first a tab then windows. 

Please provide any additional information below. Attach a screenshot if possible.
The following variables do NOT change the behavior:
    - using "_blank"
    - sleeping (setTimeout) even 10 seconds between calls
    - making sure the opener tab stays in the foreground
    - choosing "Allow all sites to show pop-ups" under "Content settings"

UserAgentString: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11


Cc: nyerramilli@chromium.org
Status: Untriaged
Labels: -OS-Mac -Area-Undefined OS-All Area-Compat Mstone-23
Able to repro this issue on Latest canary 25.0.1337.0,Beta 24.0.1312.25 on Win7,Mac 10.8.2 and Ubuntu 12.04

Here is the bisect info:

Good Build : 23.0.1264.0
Bad Build : 23.0.1265.0

You are probably looking for a change made after 156336 (known good), but no lat
er than 156357 (first known bad).
WEBKIT CHANGELOG URL:
  http://trac.webkit.org/log/trunk/?rev=128306&stop_rev=128269&verbose=on&limit=
10000
CHANGELOG URL:
  http://build.chromium.org/f/chromium/perf/dashboard/ui/changelog.html?url=/tru
nk/src&range=156336%3A156357

Comment 2 by l...@monda.hu, Feb 11, 2013
I can confirm that the following browsers are affected:

* Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.68 Safari/537.17
* Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Ubuntu Chromium/24.0.1312.56 Chrome/24.0.1312.56 Safari/537.17

Comment 3 by pauljohn...@gmail.com, Feb 15, 2013
Can reproduce this using the JS on http://tab.bz/9m5hn (hit the blue button to trigger opening the links).

Chrome Version 24.0.1312.52

Issue not present in FF 18.0.2 or IE10

Project Member Comment 4 by bugdro...@chromium.org, Mar 10, 2013
Labels: -Area-Compat -Type-Bug -Mstone-23 Type-Compat M-23
I've been having a look at this as my first bug (please be gentle!).

As far as I can tell the source of the bug is to do with whether the event is considered to be caused by a "user gesture".

In particular the following code in RenderViewImpl::show in content/renderer/render_view_impl.cc looks to be the cause of the issue

.......

  if (GetContentClient()->renderer()->AllowPopup())
    opened_by_user_gesture_ = true;

  // Force new windows to a popup if they were not opened with a user gesture.             
  if (!opened_by_user_gesture_) {
    // We exempt background tabs for compat with older versions of Chrome.                 
    // TODO(darin): This seems bogus.  These should have a user gesture, so                
    // we probably don't need this check.                                                  
    if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
          policy = WebKit::WebNavigationPolicyNewPopup;
  }

.......

This code seems wrong for a couple of reasons:
1) The call to AllowPopup will always return false as this is just a stub function in content/public/renderer/content_renderer_client.cc and popup blocking actually happens in chrome::AddWebContents in chrome/browser/ui/browser_tabstrip.cc .
2) It's unclear why we'd want to open new windows rather than new tabs in this case. If the user doesn't trust the site (i.e popups are blocked) then it won't matter either way. If the user does trust the site then why are we overriding the site in this specific case?

If it were my call then I think I'd just remove that entire chunk of code. That said I can see this isn't a clear cut technical issue so could someone from the Chromium team comment on the desired behaviour and then we can either remove the code or close the bug as invalid.

If the code is to be removed then I'd be happy to create a patch. I realise it's a trivial change but it'd be useful to learn the processes involved.
Just to expand on my second point as I realise it was a little unclear.

The logic that blocks popups is based on whether popups are allowed for the current page and whether the window was opened due to a user gesture (i.e it is not based on whether the page is opened with type NewPopup). So with the proposed code removal the second (and subsequent) new tab is still blocked until you explicitly allow popups for that domain or allow them globally. I've tested this locally.

Hope that is a bit clearer.
Comment 7 by ari.sper...@gmail.com, Mar 30, 2013
Would be great if you can provide a fix!  Looking forward to it.
Comment 8 by stevesou...@gmail.com, Sep 16, 2013
Any update on this? It's the #1 reason why I don't use Chrome as my primary browser every day.
Comment 9 by luke.a.p...@gmail.com, Sep 26, 2013
We think this is causing an issue for us where by we call window.open and want it to appear in a pop-up (not in a tab) and it is appearing in a tab. All other browsers open in a window.
Will this ever be fixed? Is there at least a work around for this? 
Thanks for looking in to this.
This bug forces me to use Firefox on a daily basis for reading most websites. Please fix??
Comment 13 by n3m...@gmail.com, Sep 12, 2014
Hi, have there been any update on this? 
Comment 14 by ...@, Nov 20, 2014
Any update? 
window.open("http://google.com","_blank" always opens in a new tab for chrome 39.0.2171.65. All other browsers consistently open google in a new window.
Comment 15 by tkent@chromium.org, Aug 27, 2015
Labels: Cr-Blink-WindowDialog
Comment 16 by tkent@chromium.org, Aug 27, 2015
Labels: Hotlist-Google
Comment 17 by tkent@chromium.org, Aug 27, 2015
Labels: Hotlist-Interop
Comment 18 by rbyers@chromium.org, Aug 27, 2015
Status: Fixed
Labels: -Hotlist-Interop
The behavior has definitely changed since this bug was filed.  We appear now to consistently suppress opening more than one window unless enabled by popup blocker settings, and consistently open as a tab by default.  You can force a window to be opened as a popup by supplying a width and height value, eg.:
  window.open('http://www.google.com/', '_blank', 'height=200,width=200');

That said, I'm sure there's still some differences between browsers here (eg. see debate here: http://stackoverflow.com/questions/726761/javascript-open-in-a-new-window-not-tab).  The relevant specs appear to leave this up to the user agent:
 https://drafts.csswg.org/cssom-view/#the-features-argument-to-the-open()-method
 https://html.spec.whatwg.org/multipage/browsers.html#dom-open

I think the remaining differences are really a UI / user preference issue, not a platform/interop issue.  But interested parties could make an argument to the spec editors to have the behavior defined more precisely for more consistent behavior between browsers.
Sign in to add a comment