incognito window first

This commit is contained in:
2020-01-15 14:05:57 +08:00
parent 790c95ffc3
commit 2224db1ad1
2 changed files with 47 additions and 8 deletions

View File

@ -22,7 +22,7 @@ export function redirectTab(tab: chrome.tabs.Tab, url: string) {
}
if (newURL == url) return url;
if (
tryCount % 5 == 0 &&
tryCount % 1 == 0 &&
!confirm('Cannot navigate to target url. \nPress OK to continue, Cancel to stop.')
) {
return Promise.reject("Tasks stopped by user.");
@ -101,13 +101,51 @@ export function scrollToBottom(tab: chrome.tabs.Tab) {
export async function createTab(url: string, active: boolean) {
return new Promise((resolve, reject) => {
chrome.tabs.create({
'url': url,
'active': active
}, function (tab) {
resolve(tab);
})
})
findIncognitoWindow().then(
incognitoWindow => {
chrome.tabs.create({
'url': url,
'active': active,
// createTab to incognito window first
'windowId': incognitoWindow ? incognitoWindow.id : undefined
}, function (tab) {
resolve(tab);
})
}
);
});
}
export async function findIncognitoWindow(): Promise<chrome.windows.Window> {
return new Promise((resolve, reject) => {
chrome.windows.getAll(
{
windowTypes: ['normal'],
},
(windows: chrome.windows.Window[]) => {
for (let window of windows) {
if (window.incognito) {
resolve(window);
return;
}
}
resolve(undefined);
}
);
});
}
export async function CreateIncognitoWindow() {
return new Promise((resolve, reject) => {
chrome.windows.create(
<chrome.windows.CreateData>{
incognito: true,
},
(window: chrome.windows.Window) => {
resolve(window);
}
);
});
}
export async function getActiveTab(currentWindow: boolean) {

View File

@ -27,6 +27,7 @@
],
"run_at": "document_idle"
}],
"incognito": "spanning",
"permissions": [
"activeTab",
"notifications"