function getActiveTab(){
return new Promise((r, reject) => {
chrome.tabs.query({
active: true,
lastFocusedWindow: true,
}, (tabs) => {
if (tabs.length){
r(tabs[0]);
} else {
chrome.tabs.query({}, tabs => {
if (tabs.length){
if (tabs.length === 1){
r(tabs[0]);
} else if (tabs.find(i => i.active)){
r(tabs.find(i => i.active))
} else {
reject("No tab found");
}
} else {
reject("No tab found");
}
})
}
})
});
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter