您好我正在创建Chrome扩展程序,故意使Chrome标签崩溃。我的方法不按我想要的方式工作。我在尝试:
chrome.tabs.update({url: "about:crash"});
chrome.tabs.update({url: "chrome://crash"});
window.location = 'about:crash';
window.location = 'chrome://crash';
这些都不起作用。
但是,如果我将网址替换为“about:blank”或“http://google.com”之类的内容,那就可以了!
Chrome是否有某种安全措施,如果是这样的话......有任何关于解决方案的建议吗?
如果可能的话,我想避免使用无限循环来重载内存。
答案 0 :(得分:6)
在标签页上加载chrome://kill
。
例如,要在chrome上删除此标签,请在网址栏中输入chrome://kill
,然后按Enter键。
Chrome 20的额外乐趣:chrome://favicon/size/1/http://gonna.crash.you/
答案 1 :(得分:4)
使用experimental processes API,您可以结束进程,包括属于选项卡的进程。
我已经想到了完全相同的用例 - 如果你完成了我的扩展,我想尝试一下!
虽然现在可能更好的想法可能是你的后台页面可以根据页面将标签重定向到数据uri,例如
data:text/html,<a href="http://www.google.com/">click here to restore</a>
或者可能是基于其查询参数生成页面的扩展页面:
my_extension_page.html?url=http://www.google.com/
答案 2 :(得分:4)
让这个工作并打包成extension。这是相关的代码:
// 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);
});
}
});
});
答案 3 :(得分:0)
tabs对象的close方法应该有序地进行,文档在这里:http://code.google.com/chrome/extensions/tabs.html#method-remove
干杯, 吨。
答案 4 :(得分:-2)
按照here所述使用以下FUN FUN LOOP!
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>!