7

Hi I'm creating a Chrome extension to purposely crash a Chrome tab. My methods are not working the way I would like. I am trying:

chrome.tabs.update({url: "about:crash"});
chrome.tabs.update({url: "chrome://crash"});
window.location = 'about:crash';
window.location = 'chrome://crash';

None of these work.

However if I replace the URL with something like 'about:blank' or 'http://google.com', it works!

Does Chrome have some sort of security measure in place, if so... any suggestions for a work around?

I would like to avoid overloading the memory with infinite loops if possible.

Andy
  • 67
  • 2
  • 7
  • 1
    I'm curious as to why you'd want to do this :) – Mitya Jul 14 '12 at 10:57
  • 2
    Check the console in your (background) page. The following error message appears: `"Error during tabs.update: I'm sorry. I'm afraid I can't do that."`. – Rob W Jul 14 '12 at 11:02
  • 1
    Yeah I'm getting "Not allowed to load local resource: chrome://crash/" and "Error during tabs.update: I'm sorry. I'm afraid I can't do that.". Reason for making this extension is that I want to force close all the tabs to free up unused memory. I'm having to manually force close them within chromes task manager at the moment. – Andy Jul 14 '12 at 16:20
  • 1
    Nice Space Odyssey reference, never noticed that... – Dagg Nabbit Jul 16 '12 at 03:24
  • @Andy, did you ever finished writing that chrome extension? I find that killing the tab with chrome://crash (better than chrome://kill) is the only solution that effectively frees RAM... – Costin Gușă Apr 18 '14 at 16:11
  • possible duplicate of [How do you force Chrome pages/tabs to crash using JavaScript?](http://stackoverflow.com/questions/10965987/how-do-you-force-chrome-pages-tabs-to-crash-using-javascript) – Camilo Martin Sep 19 '14 at 02:26

5 Answers5

7

Load chrome://kill on the tab.

For example, to kill this tab on chrome, enter chrome://kill in the URL bar and hit enter.

Extra fun as of Chrome 20: chrome://favicon/size/1/http://gonna.crash.you/

Camilo Martin
  • 37,236
  • 20
  • 111
  • 154
  • kill just crashes and reloads the tab – Andy Jul 21 '12 at 11:59
  • @Andy In my case it displays the regular "it's dead, Jim" (or something like that) message and it stays there until you reload it manually. Tested on Chrome 20 on Windows and Linux. – Camilo Martin Jul 21 '12 at 14:03
  • This works very good for me. Any ideas how to make it "go to" the `chrome://kill` page with a keystroke? Writing it by hand is not fast enough for me. – Szymon Jeż Dec 03 '13 at 12:23
  • @Jeznet Well, short of making an userscript or Chrome extension that hooks up a key combination, you can make a bookmark to `chrome://kill`. I didn't think it would work, but alas it does :) But... why do you want to kill so many pages? – Camilo Martin Dec 03 '13 at 19:09
  • @CamiloMartin Fot the same reason as in this comment: http://stackoverflow.com/questions/11483104/purposely-crash-chrome-tab-for-chrome-extension/11588312?noredirect=1#comment15185975_11489337 – Szymon Jeż Dec 04 '13 at 09:35
  • @Jeznet well, you know, what saves my skin is bookmarks. When I have a tab for too much time sitting there I think "You know what? Time to bookmark it and forget about it". – Camilo Martin Dec 04 '13 at 14:54
  • This can be executed from the background script. There is one problem though. The tab's url changes to `chrome://kill`. This means the crashed tabs cannot be bookmarked. One would like to have the url unchanged... a cumbersome solution would be to duplicate the tab hoping that the new tab will also start in the same process and then kill that new tab, removing it afterwards. – Roland Pihlakas Dec 28 '14 at 04:42
  • I also tried redirecting from `onBeforeRequest` handler to `chrome://kill` url, but it did not work from there due to permissions error. Strange then that `chrome.tabs.update` does permit directing the tab to this url. – Roland Pihlakas Dec 28 '14 at 05:48
  • @RolandPihlakas Why would you want to bookmark a crashed tab? – Camilo Martin Dec 29 '14 at 18:58
  • @CamiloMartin Of course I would want to bookmark it! If I would not care about the tab anymore at all, I would close it instead of crashing it! Crashing means very most likely that the user intends to keep the tab open, postpone reading it, therefore release the resources temporarily, and return later. I am curious, what did You think the motivation of crashing the tabs was? – Roland Pihlakas Dec 30 '14 at 04:39
  • @RolandPihlakas I thought you were trying to debug something (I don't think the feature was even intended for saving RAM). If you just want to read it later and save RAM, why not just bookmark it and keep it in the bookmarks bar instead? – Camilo Martin Dec 31 '14 at 02:04
  • @CamiloMartin I think most people use it for saving RAM or CPU (or both). For what it was intended originally, does not seem too relevant? Bookmark is next level from killing a tab. Bookmark is too hidden. BUT when I do kill the tab, I still want to keep the bookmark option open for a later time. So I could want for example bookmark the whole window later without a mess. – Roland Pihlakas Dec 31 '14 at 11:32
  • @RolandPihlakas It was certainly *not* intended for that. Go to `chrome://about/` and see how it says *"The following pages are for debugging purposes only"*. Also, clicking on the bookmarks bar is not any more "hidden" than clicking on a tab a few pixels above it. It's even roughly the same size of clicking area, and doesn't need process-killing shenanigans that can have side effects because there's no internal clean-up when you forcibly kill a process. – Camilo Martin Jan 01 '15 at 14:14
  • @CamiloMartin Obviously people have more bookmarks than open tabs... also there is the issue of multiple windows. So I don't think bookmarks bar could replace killed tabs. But I am unsure why do we discuss it here. All these arguments could be clearly visible to both of us without any discussion. I think, when people care about ergonomics then they might not always care about "rules". Especially, when the rules are programmed and therefore can be changed or broadened. – Roland Pihlakas Jan 01 '15 at 16:28
  • @RolandPihlakas Yes, but you do understand you're killing a whole process (which might have side effects) just for the sake of keeping a tab open without a few MB RAM consuption? Heck, now that I check it, my unused tabs are taking as little ~2 MB RAM and basically no CPU: http://i.imgur.com/g1nsP4m.png (and my computer is low-mid end). If your computer is slow, there may be other issues at play and you may be able to fix it without resorting to such extremes. – Camilo Martin Jan 02 '15 at 01:14
  • @CamiloMartin Regarding resources, Your mileage may vary... no point in arguing about that. I have good overview of the situation regarding that topic. But about which side effects do You worry so much specifically to undertake all that effort here - ? If the side effects are unacceptable then they are already taken care of, or will be, since manually killing tabs for debugging purposes (using Chrome task manager or the killtab url You provided) should not trigger unacceptable side effects either. – Roland Pihlakas Jan 02 '15 at 02:31
4

With the experimental processes API, you can end processes, including those that belong to tabs.

I have thought of that exact same use case - if you ever complete your extension I'd like to try it!

Though maybe a better idea for now could be for your background page could redirect tabs to a data uri based on the page, such as

data:text/html,<a href="http://www.google.com/">click here to restore</a>

or maybe an extension page that generates pages based on its query parameters:

my_extension_page.html?url=http://www.google.com/
gengkev
  • 1,890
  • 2
  • 20
  • 31
  • I think this is the best answer. Although the public stable release of Chrome doesn't come with this API, it's probably something to look out for if the process API makes it way to stable releases. – Andy Jul 21 '12 at 12:02
4

Got this working and packaged up as an extension. Here's the relevant code:

// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
  queryInfo = new Object();
  chrome.tabs.query(queryInfo, function(result) {
    var i;
    for (i=0; i < result.length; i += 1) {
        chrome.experimental.processes.getProcessIdForTab(result[i].id, function(processId) {
            chrome.experimental.processes.terminate(processId);
        });
    }
  });
});
funroll
  • 35,925
  • 7
  • 54
  • 59
  • 1
    Excellent! The plugin works. Do you know how I could get this to run when Chrome starts up, to kill all the new tabs? My objective is to keep my many tabs from choking all my system resources when Chrome starts up, so they can be loaded as-needed later. – Eliot Nov 06 '13 at 18:29
  • @Eliot I really appreciate the feedback, thanks. Searched for `chrome extension run when chrome starts` but didn't find too much. When I was using this a lot I would usually just click it repeatedly during startup. – funroll Nov 07 '13 at 04:10
  • @funroll the mentioned extension does not work for me. Tried on Chrome dev Version 36.0.1941.0 dev-m. does it work for you on chrome dev or canary builds? (try canary, as it will create a separate profile so it won't interfere with existing profile) – Costin Gușă Apr 18 '14 at 16:35
  • @CostinGușă Haven't updated the extension in a while--happy to merge a pull request if you want to get it working with the latest Chrome. – funroll Apr 20 '14 at 05:44
  • @funroll I'm not sure what exactly must I do. shall we continue the discussion on the issues page of github, can I fill an issue about this? – Costin Gușă Apr 26 '14 at 10:36
0

The close methods of the tabs object should do that in an orderly fashion, documentation is here : http://code.google.com/chrome/extensions/tabs.html#method-remove

Cheers, T.

tomdemuyt
  • 4,572
  • 2
  • 31
  • 60
  • 1
    Sorry no, that is not what I'm looking for. That closes the tab completely. I am wanting a way to crash the tab. – Andy Jul 15 '12 at 13:11
  • This will release and free up the unused memory as per why you wanted this ? – tomdemuyt Jul 15 '12 at 17:07
  • 7
    Yes however I want the ability to keep the tabs open, but not have them in memory. So much memory is wasted with idling tabs that many of us keep open for days/weeks/months. I find simply crashing them out by either ending the process or about:crash clears it from memory but I can refresh the tab later to reload the page before it was closed off. I know it's an odd request, but there is method to my madness, honestly :) And I forgot to say before, thank you for your advice! – Andy Jul 15 '12 at 21:43
-2

Use following FUN FUN LOOP as described here!

txt = "a";
while(1)
{
    txt = txt += "a";    //add as much as the browser can handle
}
//<i>[evil laugh]</i> BOOM! All memory used up, and it is now <b>CRASHED</b>!
Community
  • 1
  • 1
azrafe7
  • 2,563
  • 1
  • 15
  • 6