Restart google chrome using javascript - 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

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.

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.com/files/location-location/location-location.html

Related

Execute Javascript code in browser via xJavascript

I am looking for how to execute javascript code in the URL bar via xJavascript.
The standard way would be xJavascript:JAVASCRIPTCODEHERE, you would remove the "x" and it would execute the code, but that is not working.
Am I doing it wrong, or is no longer possible?
Please help!
I'm not sure what browser you are on but this is what I use:
javascript: (() => { document.title = "Hello World";})();
It also might not be working because you are running it on a new tab (which doesn't work for chrome)
If you are using this feature frequirently, make a bookmark with javascript:... code.
If you want to run some random JS while editing this JS, use Devtools (F12 or Ctrl+Shift+I in browser), Sources tab on top, Snippets tab on left. Snippets are persistent, editable, may run on any page.
If you want to run the same code on every page of a website, try https://chrome.google.com/webstore/detail/user-javascript-and-css/nbhcbdghjpllgmfilhnhkllmkecfmpld or Tampermonkey

Chrome disabled javascript and doesn't allow to enable it

I am not able to enable javascript in Chrome. Under Chrome javascript setting the default option for "sites can use javascript" is grayed out. Even if I add website manually under "Allowed to use javascript" the website is not loading, screenshot below.
This happened while I was trying to find a solution for another issue and followed solution from this page (the top answer), so I went to Chrome Devtools > Sources and clicked on the pause button since then the javascript has got disabled. Paused in debugger in chrome?
Note: Javascript is working fine in other Chrome Profiles. The issue is with this particular Chrome Profile.
Try right-clicking the "Sites can use Javascript" option, and inspect element:
Then, remove the disabled or disabled="" attribute from whatever element the console brings you to.
The option should be enabled. Click it and try reloading your site again.
If this doesn't work, you can try reporting any problems for whatever chrome has (I use Mozilla Firefox and I know they have a help center).
Or try re-installing the browser, because some files may be corrupt (don't worry, if you have an account you can sign-in after the reinstallation and everything should be synced).

Chrome JS console, how to run in the background?

Hi I'm trying to run a loop in Google Chrome JS console. But the script seems to pause/freeze whenever I minimize or move to another window.
How can I make it so it runs in the background until I manually stop it?
This is a general problem with every loop script I try in Chrome.
This is caused by unused tabs being frozen to save memory, resources and battery (a feature originally released in Chrome 46).
You can disable it for any given tab or domain, by navigating to chrome://discards, then toggling Auto Discardable for your desired tab.
There's also DoNotDiscard is a simple extension that prevents Chrome from suspending all tabs.

javascript redirect only works in IE after showing the IE dev console

I came across the weirdest bug. All i wanted to do is send a form using jquery and in the callback redirect the user to another page, like:
window.location.href = "index.php?p=admin";
Which from what i can find should work in all browsers.
And it does, except in IE8/9 where it only does that after i hit F12 to show the dev console! After that i need to close the browser for the redirect to NOT work again.
Anyone know why this happens and know a better way to redirect to another local page using javascript that works in IE without being affected by this crazy bug?
Are you using any of the console. functions? They aren't defined until showing the dev console and will stop the script from executing.
Have you tried?
window.location.replace("index.php?p=admin");

jQuery .load(): loading a div when click

I would like to achieve that when clicking in an image, in the div where this image is, a div with other content from another .html is loaded, but I can't get it done.
If I do, the following, it works perfectly:
$('#windows_link').click(function(){
$('#apps_container').html("Hi!");
});
But if I do the following, it does not work; it doesn't do anything actually:
$('#windows_link').click(function(){
$('#apps_container').load('windows_apps.html #apps_container');
});
Any help, please?
Thanks a lot in advance!
When you're local any other HTML path is treated as another domain in certain browsers (Chrome is on the list). That means any AJAX request (what .load() does underneath) you attempt will be blocked by the same origin policy.
What you have will likely work fine...just not locally, in Chrome.
You can verify this by testing in another browser like Firefox, or by launching chrome with a command line switch to disable this safety feature (only for testing!, turn it off after):
chrome.exe --disable-web-security
If the first try works correctly, i assume the problem is here
.load('windows_apps.html #apps_container');
When you click the link, do you see a call in your .net panel of firebug or of your debugging console(does the ajax call complete succesfully)?
Is windows_apps.html in the same folder of the page script that calls it?
is there a div called apps_container into that page?

Categories