最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Restart google chrome using javascript - Stack Overflow

programmeradmin4浏览0评论

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

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

Share Improve this question asked May 29, 2012 at 1:46 G-ManG-Man 7,24118 gold badges73 silver badges101 bronze badges 3
  • Are you building a plugin or is this JS on a webpage? – Joseph Commented May 29, 2012 at 1:47
  • It is the JS on the webpage. chrome://flags opens a webpage ( I can view the source) but I cannot figure out what causes the browser to restart on the click of the button that is on the page. I do not see any code – G-Man Commented May 29, 2012 at 1:47
  • 1 Take a look at this: stackoverflow./a/4551244/464257 – Shaz Commented May 29, 2012 at 2:00
Add a ment  | 

4 Answers 4

Reset to default 8

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 ment implies, it hooks into the C++ code behind Chrome, which will attempt a restart.

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.

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:"

Entering the following into the address bar restarts Chrome:

> chrome:restart

But you'll need to find a way to call it: http://www.phpied./files/location-location/location-location.html

发布评论

评论列表(0)

  1. 暂无评论