Skip to content

Instantly share code, notes, and snippets.

@kitsunde
Created July 10, 2011 15:40
Show Gist options
  • Select an option

  • Save kitsunde/1074629 to your computer and use it in GitHub Desktop.

Select an option

Save kitsunde/1074629 to your computer and use it in GitHub Desktop.
If we fail to change the dimensions of a chrome window we create a new one with the desired dimensions and migrate the tabs.
// Workaround for http://code.google.com/p/chromium/issues/detail?id=50138
chrome.windows.getCurrent(function(win){
var update = {height: 480, width: 320};
chrome.windows.update(win.id, update, function(win){
// If the window isn't the dimensions we set to it
// it means it's maximized and we'll create a new window.
if( win.height !== update.height && win.width !== update.width ){
chrome.tabs.getAllInWindow(win.id, function(tabs){
// Find the tab that was selected in the original window.
var selected = tabs.filter(function(tab){return tab.selected;})[0];
// We can move one tab over "for free" when we create the window.
// This also means we don't have to destroy the empty tab that comes
// with creating a new window.
update.tabId = tabs.pop().id;
chrome.windows.create(update, function(newwin){
// Preserve tab order by appending them in reverse.
var appended = 1;
tabs.reverse().forEach(function(tab){
chrome.tabs.move(tab.id, { windowId: newwin.id, index: 0 }, function(){
// When we are done moving all the tabs over focus the
// originally selected tab
if(appended < tabs.length){
appended++;
}else{
chrome.tabs.update(selected.id, {selected: true});
}
});
});
});
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment