Reputation: 720
I'm trying to make an extension that crashes all tabs in chrome window so that they don't load on opening chrome (when having too many tabs).
But when I try to use
chrome.tabs.update(null, {url:"chrome://crash"})
or
chrome.tabs.update(null, {url:"about:crash"})
they don't work, although using
chrome.tabs.update(null, {url:"chrome://tasks"})
works well
Is there any workaround to do that?
when this works too I'd like to loop on all the open tabs to do the same thing and I don't know how.
Upvotes: 3
Views: 1905
Reputation: 1336
you can simply getAll active windows and loop through its tabs then change its url to data:text/html
chrome.windows.getAll({populate : true}, function (window_list) {
var list = [];
for(var i=0;i<window_list.length;i++) {
list = list.concat(window_list[i].tabs);
}
for(var y=0;y<list.length;y++) {
var jsRunner = {'code': 'window.stop()'};
chrome.tabs.executeScript(list[y].id, jsRunner);
if(!list[y].url.match(/data\:text\/html/gi)){
chrome.tabs.update(list[y].id, {url:"data:text/html,<meta charset=\"utf-8\"><title>" + list[y].title + "</title><h1 style='text-align:center;'><a style='text-decoration:none;' href='" + list[y].url + "'>" + list[y].url + "</a></h1>"});
}
}
});
you can download the extension and try it http://d.pr/f/wXaZ
Upvotes: 3