Wednesday, December 17, 2008

Google Chrome : How can a web page open a new tab in a separate process?

Google Chrome has a multi-process architecture, meaning tabs can run in separate processes from each other, and from the main browser process. New tabs spawned from a web page, however, are usually opened in the same process, so that the original page can access the new tab using JavaScript.

If you'd like a new tab to open in a separate process:

* 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 any URL on a different domain, port, or protocol than that of the page spawning the pop-up. For example, if the page spawning the pop-up is on http://www.example.com/:
o a different domain would be http://www.example.org
o a different port would be http://www.example.com:8080
o a different protocol would be https://www.example.com

Google Chrome will recognize these actions as a hint that the new and old pages should be isolated from each other, and will attempt to load the new page in a separate process.

The following code snippet can be used to accomplish all of these steps:

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

No comments:

Post a Comment