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

javascript - Purposely Crash Chrome Tab for Chrome Extension - Stack Overflow

programmeradmin11浏览0评论

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 '', 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.

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.

Share Improve this question edited Jul 14, 2012 at 11:31 Andy asked Jul 14, 2012 at 10:44 AndyAndy 772 silver badges8 bronze badges 6
  • 1 I'm curious as to why you'd want to do this :) – Mitya Commented Jul 14, 2012 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 Commented Jul 14, 2012 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 Commented Jul 14, 2012 at 16:20
  • 1 Nice Space Odyssey reference, never noticed that... – Dagg Nabbit Commented Jul 16, 2012 at 3: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șă Commented Apr 18, 2014 at 16:11
 |  Show 1 more comment

5 Answers 5

Reset to default 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/

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);
        });
    }
  });
});

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/

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.

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>!
发布评论

评论列表(0)

  1. 暂无评论