From e9c3a61e553bad7fd29c37cc393b2f6fdf21ce40 Mon Sep 17 00:00:00 2001 From: QLHazyCoder <2825305047@qq.com> Date: Sun, 26 Apr 2026 17:19:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20Plus=20Return=20?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E6=97=B6=E9=97=B4=E8=87=B3=2040=20=E7=A7=92?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- background.js | 1 - background/steps/plus-return-confirm.js | 6 +-- tests/plus-return-confirm-wait.test.js | 53 +++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 tests/plus-return-confirm-wait.test.js diff --git a/background.js b/background.js index ac3edd5..2ef4de9 100644 --- a/background.js +++ b/background.js @@ -7109,7 +7109,6 @@ const plusReturnConfirmExecutor = self.MultiPageBackgroundPlusReturnConfirm?.cre isTabAlive, setState, sleepWithStop, - waitForTabCompleteUntilStopped, waitForTabUrlMatchUntilStopped, }); const step10Executor = self.MultiPageBackgroundStep10?.createStep10Executor({ diff --git a/background/steps/plus-return-confirm.js b/background/steps/plus-return-confirm.js index c233dc6..62cc703 100644 --- a/background/steps/plus-return-confirm.js +++ b/background/steps/plus-return-confirm.js @@ -3,6 +3,7 @@ })(typeof self !== 'undefined' ? self : globalThis, function createBackgroundPlusReturnConfirmModule() { const PAYPAL_SOURCE = 'paypal-flow'; const PLUS_CHECKOUT_SOURCE = 'plus-checkout'; + const PLUS_RETURN_SETTLE_WAIT_MS = 40000; function createPlusReturnConfirmExecutor(deps = {}) { const { @@ -12,7 +13,6 @@ isTabAlive, setState, sleepWithStop, - waitForTabCompleteUntilStopped, waitForTabUrlMatchUntilStopped, } = deps; @@ -41,8 +41,8 @@ const tabId = await resolveReturnTabId(state); await addLog('步骤 9:正在等待 PayPal 授权后回跳到 ChatGPT / OpenAI 页面...', 'info'); const tab = await waitForTabUrlMatchUntilStopped(tabId, isReturnUrl); - await waitForTabCompleteUntilStopped(tabId); - await sleepWithStop(1000); + await addLog('步骤 9:已检测到订阅回跳页面,固定等待 40 秒让页面完成加载。', 'info'); + await sleepWithStop(PLUS_RETURN_SETTLE_WAIT_MS); await setState({ plusCheckoutTabId: tabId, diff --git a/tests/plus-return-confirm-wait.test.js b/tests/plus-return-confirm-wait.test.js new file mode 100644 index 0000000..db7029b --- /dev/null +++ b/tests/plus-return-confirm-wait.test.js @@ -0,0 +1,53 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); + +const source = fs.readFileSync('background/steps/plus-return-confirm.js', 'utf8'); +const globalScope = {}; +const api = new Function('self', `${source}; return self.MultiPageBackgroundPlusReturnConfirm;`)(globalScope); + +test('Plus return confirm waits a fixed 40 seconds after return URL is detected', async () => { + const events = []; + const executor = api.createPlusReturnConfirmExecutor({ + addLog: async (message, level = 'info') => { + events.push({ type: 'log', message, level }); + }, + completeStepFromBackground: async (step, payload) => { + events.push({ type: 'complete', step, payload }); + }, + getTabId: async (source) => (source === 'paypal-flow' ? 77 : null), + isTabAlive: async (source) => source === 'paypal-flow', + setState: async (payload) => { + events.push({ type: 'set-state', payload }); + }, + sleepWithStop: async (ms) => { + events.push({ type: 'sleep', ms }); + }, + waitForTabUrlMatchUntilStopped: async (tabId, matcher) => { + const url = 'https://chatgpt.com/backend-api/payments/success'; + assert.equal(tabId, 77); + assert.equal(matcher(url), true); + events.push({ type: 'url-match', tabId, url }); + return { id: tabId, url }; + }, + }); + + await executor.executePlusReturnConfirm({}); + + assert.deepEqual( + events.find((event) => event.type === 'sleep'), + { type: 'sleep', ms: 40000 } + ); + assert.equal( + events.some((event) => event.type === 'log' && /固定等待 40 秒/.test(event.message)), + true + ); + assert.deepEqual( + events.find((event) => event.type === 'complete'), + { + type: 'complete', + step: 9, + payload: { plusReturnUrl: 'https://chatgpt.com/backend-api/payments/success' }, + } + ); +});