Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart google chrome using javascript

In chrome, if I go to chrome://flags/ and make a change on the flags page ( enable/disabe features ), a button appears at the bottom of the page which when clicked restarts chrome and re-opens the pages that were opened. Does anyone know what javascript code allows that to happen ?

This is the html where the button appears

<div class="needs-restart" jsdisplay="needsRestart">
        <div i18n-content="flagsRestartNotice">NEEDS_RESTART</div>
        <button class="experiment-restart-button"
                type="button"
                i18n-content="flagsRestartButton">RESTART</button>
</div>

Thanks

like image 582
G-Man Avatar asked May 29 '12 01:05

G-Man


People also ask

How do I force a browser to restart?

Hold down the Ctrl key and press the F5 key, or hold the Ctrl key and click the Refresh button.

How do I restart Chrome on Linux?

Close and Reopen Chrome on Windows, Linux, and Chromebook To quit and then reopen Chrome on your Windows, Linux, or Chromebook computer click the “X” icon in Chrome's top-right corner. This closes the browser. To now launch Chrome, search for “Chrome” in your app drawer and select it. This reopens the browser.


3 Answers

A restartBrowser() function is called from the click of that button.

From flags.js:

/**
 * Asks the C++ FlagsDOMHandler to restart the browser (restoring tabs).
 */
function restartBrowser() {
  chrome.send('restartBrowser');
}

Like the comment implies, it hooks into the C++ code behind Chrome, which will attempt a restart.

like image 71
Stephen Avatar answered Oct 12 '22 07:10

Stephen


Javascript by itself does not allow you to restart the browser. If it did, websites could restart your browser whenever they wanted, which would be annoying for the user. The chrome://flags/ has special permission to interact with the browser and tell it to request a restart. This code is not shown; it's part of Chrome.

like image 31
wecsam Avatar answered Oct 12 '22 07:10

wecsam


I think there is no javascript solution for that but you can type in the url bar : chrome://restart

in order to restart google chrome manually.

If you try this trick using Javascript:

window.location = 'chrome://restart';

then you will get an error message that says "Not allowed to load local resource:"

like image 38
ismnoiet Avatar answered Oct 12 '22 07:10

ismnoiet