Skip to content

Instantly share code, notes, and snippets.

@Sleavely
Created August 31, 2018 21:09
Show Gist options
  • Select an option

  • Save Sleavely/03c6ea33bce4542dd78a0e26f33b1297 to your computer and use it in GitHub Desktop.

Select an option

Save Sleavely/03c6ea33bce4542dd78a0e26f33b1297 to your computer and use it in GitHub Desktop.
An IIFE that moves your Chrome tab to a new window. Must be run from an extension with appropriate permissions.
(() => {
const _currentTab = new Promise((resolve) => {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
resolve(tabs[0])
})
});
const _currentWindow = new Promise((resolve) => {
chrome.windows.getCurrent((win) => resolve(win))
});
(async () => {
const currentTab = await _currentTab
const currentWindow = await _currentWindow
// Let's cherrypick the options we want to clone
const windowOpts = {
tabId: currentTab.id,
focused: true,
incognito: currentWindow.incognito,
type: currentWindow.type
}
// Cant set dimensions and pos manually for some states
if(['minimized', 'maximized', 'fullscreen'].indexOf(currentWindow.state) !== -1)
{
windowOpts.state = currentWindow.state
}
else
{
windowOpts.top = currentWindow.top
windowOpts.left = currentWindow.left
windowOpts.height = currentWindow.height
windowOpts.width = currentWindow.width
}
chrome.windows.create(windowOpts)
})()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment