|
@@ -1,12 +1,13 @@
|
|
import browser from 'webextension-polyfill';
|
|
import browser from 'webextension-polyfill';
|
|
import { isWhitespace, sleep } from '@/utils/helper';
|
|
import { isWhitespace, sleep } from '@/utils/helper';
|
|
import {
|
|
import {
|
|
- getBlockConnection,
|
|
|
|
|
|
+ waitTabLoaded,
|
|
attachDebugger,
|
|
attachDebugger,
|
|
sendDebugCommand,
|
|
sendDebugCommand,
|
|
|
|
+ getBlockConnection,
|
|
} from '../helper';
|
|
} from '../helper';
|
|
|
|
|
|
-async function newTab(block) {
|
|
|
|
|
|
+async function newTab({ outputs, data }) {
|
|
if (this.windowId) {
|
|
if (this.windowId) {
|
|
try {
|
|
try {
|
|
await browser.windows.get(this.windowId);
|
|
await browser.windows.get(this.windowId);
|
|
@@ -15,18 +16,16 @@ async function newTab(block) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- const nextBlockId = getBlockConnection(block);
|
|
|
|
|
|
+ const nextBlockId = getBlockConnection({ outputs });
|
|
|
|
|
|
try {
|
|
try {
|
|
- const { updatePrevTab, url, active, inGroup, customUserAgent, userAgent } =
|
|
|
|
- block.data;
|
|
|
|
- const isInvalidUrl = !/^https?/.test(url);
|
|
|
|
|
|
+ const isInvalidUrl = !/^https?/.test(data.url);
|
|
|
|
|
|
if (isInvalidUrl) {
|
|
if (isInvalidUrl) {
|
|
const error = new Error(
|
|
const error = new Error(
|
|
- isWhitespace(url) ? 'url-empty' : 'invalid-active-tab'
|
|
|
|
|
|
+ isWhitespace(data.url) ? 'url-empty' : 'invalid-active-tab'
|
|
);
|
|
);
|
|
- error.data = { url };
|
|
|
|
|
|
+ error.data = { url: data.url };
|
|
|
|
|
|
throw error;
|
|
throw error;
|
|
}
|
|
}
|
|
@@ -34,25 +33,28 @@ async function newTab(block) {
|
|
let tab = null;
|
|
let tab = null;
|
|
const isChrome = BROWSER_TYPE === 'chrome';
|
|
const isChrome = BROWSER_TYPE === 'chrome';
|
|
|
|
|
|
- if (updatePrevTab && this.activeTab.id) {
|
|
|
|
- tab = await browser.tabs.update(this.activeTab.id, { url, active });
|
|
|
|
|
|
+ if (data.updatePrevTab && this.activeTab.id) {
|
|
|
|
+ tab = await browser.tabs.update(this.activeTab.id, {
|
|
|
|
+ url: data.url,
|
|
|
|
+ active: data.active,
|
|
|
|
+ });
|
|
} else {
|
|
} else {
|
|
tab = await browser.tabs.create({
|
|
tab = await browser.tabs.create({
|
|
- url,
|
|
|
|
- active,
|
|
|
|
|
|
+ url: data.url,
|
|
|
|
+ active: data.active,
|
|
windowId: this.windowId,
|
|
windowId: this.windowId,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- this.activeTab.url = url;
|
|
|
|
|
|
+ this.activeTab.url = data.url;
|
|
if (tab) {
|
|
if (tab) {
|
|
- if (this.settings.debugMode || customUserAgent) {
|
|
|
|
|
|
+ if (this.settings.debugMode || data.customUserAgent) {
|
|
await attachDebugger(tab.id, this.activeTab.id);
|
|
await attachDebugger(tab.id, this.activeTab.id);
|
|
this.debugAttached = true;
|
|
this.debugAttached = true;
|
|
|
|
|
|
- if (customUserAgent && isChrome) {
|
|
|
|
|
|
+ if (data.customUserAgent && isChrome) {
|
|
await sendDebugCommand(tab.id, 'Network.setUserAgentOverride', {
|
|
await sendDebugCommand(tab.id, 'Network.setUserAgentOverride', {
|
|
- userAgent,
|
|
|
|
|
|
+ userAgent: data.userAgent,
|
|
});
|
|
});
|
|
await browser.tabs.reload(tab.id);
|
|
await browser.tabs.reload(tab.id);
|
|
await sleep(1000);
|
|
await sleep(1000);
|
|
@@ -63,7 +65,7 @@ async function newTab(block) {
|
|
this.windowId = tab.windowId;
|
|
this.windowId = tab.windowId;
|
|
}
|
|
}
|
|
|
|
|
|
- if (inGroup && !updatePrevTab) {
|
|
|
|
|
|
+ if (data.inGroup && !data.updatePrevTab) {
|
|
const options = {
|
|
const options = {
|
|
groupId: this.activeTab.groupId,
|
|
groupId: this.activeTab.groupId,
|
|
tabIds: this.activeTab.id,
|
|
tabIds: this.activeTab.id,
|
|
@@ -84,7 +86,7 @@ async function newTab(block) {
|
|
|
|
|
|
this.activeTab.frameId = 0;
|
|
this.activeTab.frameId = 0;
|
|
|
|
|
|
- if (isChrome && !this.settings.debugMode && customUserAgent) {
|
|
|
|
|
|
+ if (isChrome && !this.settings.debugMode && data.customUserAgent) {
|
|
chrome.debugger.detach({ tabId: tab.id });
|
|
chrome.debugger.detach({ tabId: tab.id });
|
|
}
|
|
}
|
|
|
|
|
|
@@ -95,9 +97,17 @@ async function newTab(block) {
|
|
await Promise.allSettled(preloadScripts);
|
|
await Promise.allSettled(preloadScripts);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ console.log(data, data.waitTabLoaded);
|
|
|
|
+ if (data.waitTabLoaded) {
|
|
|
|
+ await waitTabLoaded(
|
|
|
|
+ this.activeTab.id,
|
|
|
|
+ this.settings?.tabLoadTimeout ?? 30000
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
return {
|
|
return {
|
|
- data: url,
|
|
|
|
nextBlockId,
|
|
nextBlockId,
|
|
|
|
+ data: data.url,
|
|
};
|
|
};
|
|
} catch (error) {
|
|
} catch (error) {
|
|
error.nextBlockId = nextBlockId;
|
|
error.nextBlockId = nextBlockId;
|