Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a new tab in separate thread with JavaScript? (chrome)

Is it possible to open a new popup tab that would run in a separate thread? To be more specific, if I create a new popup tab and start debugging in that new tab, tab which contains link will also pause javascript until I click resume in a new tab. What I want to achieve is to create a new tab that is separated so I can debug it while parent tab continues running. I have this problem using Chrome browser. Note that this works fine in Firefox (haven't tested in other browsers).

like image 696
Vedran Jukic Avatar asked Sep 19 '16 13:09

Vedran Jukic


2 Answers

The current version of Chrome does not appear to use a separate thread when using the null opener trick that domagojk referenced. However, if you're in a javascript handler you can still take advantage of the noreferrer link trick he mentions:

        var e = document.createElement("a");
        e.href="/index.html";
        e.target="_blank";
        e.rel = "noreferrer";
        e.click();
like image 195
StriplingWarrior Avatar answered Oct 20 '22 21:10

StriplingWarrior


Usually chrome forces new window to run on the same Process ID. But, there are techniques which allows sites to open a new window without forcing it into the same process:

Use a link to a different web site that targets a new window without passing on referrer information.

<a href="http://differentsite.com" target="_blank" rel="noreferrer">Open in new tab and new process</a>

If you want the new tab to open in a new process while still passing on referrer information, you can use the following steps in JavaScript:

  • Open the new tab with about:blank as its target.
  • Set the newly opened tab's opener variable to null, so that it can't access the original page.
  • Redirect from about:blank to a different web site than the original page.

For example:

var w = window.open();
    w.opener = null;
    w.document.location = "http://differentsite.com/index.html";

Technically the original website still has access to the new one through w, but they treat .opener=null as a clue to neuter the window.

Source: https://bugzilla.mozilla.org/show_bug.cgi?id=666746

like image 38
domagojk Avatar answered Oct 20 '22 21:10

domagojk