fix(tabs): scope payment task tab lookup
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
addLog: rawAddLog = async () => {},
|
addLog: rawAddLog = async () => {},
|
||||||
chrome,
|
chrome,
|
||||||
completeStepFromBackground,
|
completeStepFromBackground,
|
||||||
|
createAutomationTab = null,
|
||||||
ensureContentScriptReadyOnTabUntilStopped,
|
ensureContentScriptReadyOnTabUntilStopped,
|
||||||
fetch: fetchImpl = null,
|
fetch: fetchImpl = null,
|
||||||
registerTab,
|
registerTab,
|
||||||
@@ -63,7 +64,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function openFreshChatGptTabForCheckoutCreate() {
|
async function openFreshChatGptTabForCheckoutCreate() {
|
||||||
const tab = await chrome.tabs.create({ url: PLUS_CHECKOUT_ENTRY_URL, active: true });
|
const tab = typeof createAutomationTab === 'function'
|
||||||
|
? await createAutomationTab({ url: PLUS_CHECKOUT_ENTRY_URL, active: true })
|
||||||
|
: await chrome.tabs.create({ url: PLUS_CHECKOUT_ENTRY_URL, active: true });
|
||||||
const tabId = Number(tab?.id);
|
const tabId = Number(tab?.id);
|
||||||
if (!Number.isInteger(tabId)) {
|
if (!Number.isInteger(tabId)) {
|
||||||
throw new Error('步骤 6:打开 ChatGPT 页面失败,无法创建订阅页。');
|
throw new Error('步骤 6:打开 ChatGPT 页面失败,无法创建订阅页。');
|
||||||
|
|||||||
@@ -88,6 +88,7 @@
|
|||||||
getTabId,
|
getTabId,
|
||||||
isTabAlive,
|
isTabAlive,
|
||||||
markCurrentRegistrationAccountUsed,
|
markCurrentRegistrationAccountUsed,
|
||||||
|
queryTabsInAutomationWindow = null,
|
||||||
setState,
|
setState,
|
||||||
sleepWithStop,
|
sleepWithStop,
|
||||||
waitForTabCompleteUntilStopped,
|
waitForTabCompleteUntilStopped,
|
||||||
@@ -1364,13 +1365,16 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const activeTabs = await chrome.tabs.query({ active: true, currentWindow: true }).catch(() => []);
|
const queryTabs = typeof queryTabsInAutomationWindow === 'function'
|
||||||
|
? queryTabsInAutomationWindow
|
||||||
|
: (queryInfo) => chrome.tabs.query(queryInfo);
|
||||||
|
const activeTabs = await queryTabs({ active: true, currentWindow: true }).catch(() => []);
|
||||||
const activeCheckoutTab = activeTabs.find((tab) => Number.isInteger(tab?.id) && isPlusCheckoutUrl(tab.url));
|
const activeCheckoutTab = activeTabs.find((tab) => Number.isInteger(tab?.id) && isPlusCheckoutUrl(tab.url));
|
||||||
if (activeCheckoutTab) {
|
if (activeCheckoutTab) {
|
||||||
return activeCheckoutTab.id;
|
return activeCheckoutTab.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkoutTabs = await chrome.tabs.query({ url: 'https://chatgpt.com/checkout/*' }).catch(() => []);
|
const checkoutTabs = await queryTabs({ url: 'https://chatgpt.com/checkout/*' }).catch(() => []);
|
||||||
const checkoutTab = checkoutTabs.find((tab) => Number.isInteger(tab?.id) && isPlusCheckoutUrl(tab.url));
|
const checkoutTab = checkoutTabs.find((tab) => Number.isInteger(tab?.id) && isPlusCheckoutUrl(tab.url));
|
||||||
return checkoutTab?.id || null;
|
return checkoutTab?.id || null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
ensureContentScriptReadyOnTabUntilStopped,
|
ensureContentScriptReadyOnTabUntilStopped,
|
||||||
getTabId,
|
getTabId,
|
||||||
isTabAlive,
|
isTabAlive,
|
||||||
|
queryTabsInAutomationWindow = null,
|
||||||
registerTab,
|
registerTab,
|
||||||
sendTabMessageUntilStopped,
|
sendTabMessageUntilStopped,
|
||||||
setState,
|
setState,
|
||||||
@@ -110,7 +111,10 @@
|
|||||||
if (!chrome?.tabs?.query) {
|
if (!chrome?.tabs?.query) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const tabs = await chrome.tabs.query({}).catch(() => []);
|
const queryTabs = typeof queryTabsInAutomationWindow === 'function'
|
||||||
|
? queryTabsInAutomationWindow
|
||||||
|
: (queryInfo) => chrome.tabs.query(queryInfo);
|
||||||
|
const tabs = await queryTabs({}).catch(() => []);
|
||||||
const candidates = (Array.isArray(tabs) ? tabs : [])
|
const candidates = (Array.isArray(tabs) ? tabs : [])
|
||||||
.filter((tab) => Number.isInteger(tab?.id) && predicate(tab.url || ''));
|
.filter((tab) => Number.isInteger(tab?.id) && predicate(tab.url || ''));
|
||||||
if (!candidates.length) {
|
if (!candidates.length) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
addLog,
|
addLog,
|
||||||
broadcastDataUpdate,
|
broadcastDataUpdate,
|
||||||
chrome,
|
chrome,
|
||||||
|
createAutomationTab = null,
|
||||||
getTabId,
|
getTabId,
|
||||||
isTabAlive,
|
isTabAlive,
|
||||||
registerTab,
|
registerTab,
|
||||||
@@ -48,7 +49,9 @@
|
|||||||
throw new Error('步骤 7:无法自动重新打开 GoPay 订阅页。');
|
throw new Error('步骤 7:无法自动重新打开 GoPay 订阅页。');
|
||||||
}
|
}
|
||||||
|
|
||||||
const tab = await chrome.tabs.create({ url: checkoutUrl, active: true });
|
const tab = typeof createAutomationTab === 'function'
|
||||||
|
? await createAutomationTab({ url: checkoutUrl, active: true })
|
||||||
|
: await chrome.tabs.create({ url: checkoutUrl, active: true });
|
||||||
const tabId = Number(tab?.id) || 0;
|
const tabId = Number(tab?.id) || 0;
|
||||||
if (!tabId) {
|
if (!tabId) {
|
||||||
throw new Error('步骤 7:重新打开 GoPay 订阅页失败。');
|
throw new Error('步骤 7:重新打开 GoPay 订阅页失败。');
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
ensureContentScriptReadyOnTabUntilStopped,
|
ensureContentScriptReadyOnTabUntilStopped,
|
||||||
getTabId,
|
getTabId,
|
||||||
isTabAlive,
|
isTabAlive,
|
||||||
|
queryTabsInAutomationWindow = null,
|
||||||
sendTabMessageUntilStopped,
|
sendTabMessageUntilStopped,
|
||||||
setState,
|
setState,
|
||||||
sleepWithStop,
|
sleepWithStop,
|
||||||
@@ -48,7 +49,10 @@
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabs = await chrome.tabs.query({}).catch(() => []);
|
const queryTabs = typeof queryTabsInAutomationWindow === 'function'
|
||||||
|
? queryTabsInAutomationWindow
|
||||||
|
: (queryInfo) => chrome.tabs.query(queryInfo);
|
||||||
|
const tabs = await queryTabs({}).catch(() => []);
|
||||||
const candidates = (Array.isArray(tabs) ? tabs : [])
|
const candidates = (Array.isArray(tabs) ? tabs : [])
|
||||||
.filter((tab) => Number.isInteger(tab?.id) && isPayPalUrl(tab.url || ''));
|
.filter((tab) => Number.isInteger(tab?.id) && isPayPalUrl(tab.url || ''));
|
||||||
if (!candidates.length) {
|
if (!candidates.length) {
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ function createExecutorHarness({
|
|||||||
fetchImpl = null,
|
fetchImpl = null,
|
||||||
getAddressSeedForCountry = () => createAddressSeed(),
|
getAddressSeedForCountry = () => createAddressSeed(),
|
||||||
getState = null,
|
getState = null,
|
||||||
|
queryTabsInAutomationWindow = null,
|
||||||
markCurrentRegistrationAccountUsed = async () => {},
|
markCurrentRegistrationAccountUsed = async () => {},
|
||||||
probeIpProxyExit = null,
|
probeIpProxyExit = null,
|
||||||
onSetState = null,
|
onSetState = null,
|
||||||
@@ -161,6 +162,7 @@ function createExecutorHarness({
|
|||||||
getTabId: async () => null,
|
getTabId: async () => null,
|
||||||
isTabAlive: async () => false,
|
isTabAlive: async () => false,
|
||||||
markCurrentRegistrationAccountUsed,
|
markCurrentRegistrationAccountUsed,
|
||||||
|
...(typeof queryTabsInAutomationWindow === 'function' ? { queryTabsInAutomationWindow } : {}),
|
||||||
setState: async (updates) => {
|
setState: async (updates) => {
|
||||||
events.states.push(updates);
|
events.states.push(updates);
|
||||||
if (typeof onSetState === 'function') {
|
if (typeof onSetState === 'function') {
|
||||||
@@ -240,6 +242,38 @@ test('Plus checkout billing uses the current checkout tab when step 6 did not re
|
|||||||
assert.equal(events.logs.some((entry) => /当前已在 Plus Checkout 页面/.test(entry.message)), true);
|
assert.equal(events.logs.some((entry) => /当前已在 Plus Checkout 页面/.test(entry.message)), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Plus checkout billing searches checkout tabs inside the locked automation window', async () => {
|
||||||
|
const queries = [];
|
||||||
|
const { checkoutTab, executor } = createExecutorHarness({
|
||||||
|
frames: [{ frameId: 0, url: 'https://chatgpt.com/checkout/openai_ie/cs_test' }],
|
||||||
|
queryTabsInAutomationWindow: async (queryInfo) => {
|
||||||
|
queries.push(queryInfo);
|
||||||
|
if (queryInfo?.active) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
if (queryInfo?.url === 'https://chatgpt.com/checkout/*') {
|
||||||
|
return [checkoutTab];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
stateByFrame: {
|
||||||
|
0: {
|
||||||
|
hasPayPal: true,
|
||||||
|
paypalCandidates: [{ tag: 'button', text: 'PayPal' }],
|
||||||
|
billingFieldsVisible: true,
|
||||||
|
hasSubscribeButton: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await executor.executePlusCheckoutBilling({});
|
||||||
|
|
||||||
|
assert.deepEqual(queries, [
|
||||||
|
{ active: true, currentWindow: true },
|
||||||
|
{ url: 'https://chatgpt.com/checkout/*' },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
test('Plus checkout billing sends the billing command to the iframe that contains PayPal', async () => {
|
test('Plus checkout billing sends the billing command to the iframe that contains PayPal', async () => {
|
||||||
const { events, executor } = createExecutorHarness({
|
const { events, executor } = createExecutorHarness({
|
||||||
frames: [
|
frames: [
|
||||||
|
|||||||
Reference in New Issue
Block a user