feat: 增强内容脚本加载逻辑,优化错误处理和测试用例

This commit is contained in:
QLHazyCoder
2026-04-26 15:29:26 +08:00
parent 7b668fdcaf
commit 336fdb0c3a
7 changed files with 174 additions and 129 deletions
+13
View File
@@ -92,3 +92,16 @@ return { shouldReportReadyForFrame };
assert.equal(api.shouldReportReadyForFrame('plus-checkout', false), true);
assert.equal(api.shouldReportReadyForFrame('paypal-flow', true), true);
});
test('getRuntimeScriptSource follows injected source overrides after utils is already loaded', () => {
const bundle = [extractFunction('getRuntimeScriptSource')].join('\n');
const api = new Function('window', 'SCRIPT_SOURCE', `
${bundle}
return { getRuntimeScriptSource };
`);
const windowRef = {};
assert.equal(api(windowRef, 'chatgpt').getRuntimeScriptSource(), 'chatgpt');
windowRef.__MULTIPAGE_SOURCE = 'plus-checkout';
assert.equal(api(windowRef, 'chatgpt').getRuntimeScriptSource(), 'plus-checkout');
});
+9 -1
View File
@@ -25,7 +25,10 @@ test('Plus checkout create does not wait 20 seconds after opening checkout page'
ensureContentScriptReadyOnTabUntilStopped: async () => {
events.push({ type: 'ready' });
},
reuseOrCreateTab: async () => 42,
reuseOrCreateTab: async (source, url, options) => {
events.push({ type: 'reuse-tab', source, url, options });
return 42;
},
sendTabMessageUntilStopped: async () => ({
checkoutUrl: 'https://checkout.stripe.com/c/pay/session',
country: 'US',
@@ -44,6 +47,11 @@ test('Plus checkout create does not wait 20 seconds after opening checkout page'
await executor.executePlusCheckoutCreate();
const reuseEvent = events.find((event) => event.type === 'reuse-tab');
assert.equal(reuseEvent.source, 'plus-checkout');
assert.equal(reuseEvent.options.reloadIfSameUrl, false);
assert.equal(Object.hasOwn(reuseEvent.options, 'inject'), false);
const sleepEvents = events.filter((event) => event.type === 'sleep');
assert.deepStrictEqual(sleepEvents.map((event) => event.ms), [1000, 1000]);