feat: 增强内容脚本加载逻辑,优化错误处理和测试用例
This commit is contained in:
+18
-2
@@ -4122,6 +4122,19 @@ async function ensureContentScriptReadyOnTab(source, tabId, options = {}) {
|
|||||||
return tabRuntime.ensureContentScriptReadyOnTab(source, tabId, options);
|
return tabRuntime.ensureContentScriptReadyOnTab(source, tabId, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isContentScriptReadyPong(source, pong) {
|
||||||
|
if (!pong?.ok) return false;
|
||||||
|
if (pong.source && pong.source !== source) return false;
|
||||||
|
if (source === 'plus-checkout') {
|
||||||
|
return Boolean(pong.plusCheckoutReady);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isUnrecoverableContentScriptInjectError(error) {
|
||||||
|
return /Could not load file/i.test(String(error?.message || error || ''));
|
||||||
|
}
|
||||||
|
|
||||||
async function ensureContentScriptReadyOnTabUntilStopped(source, tabId, options = {}) {
|
async function ensureContentScriptReadyOnTabUntilStopped(source, tabId, options = {}) {
|
||||||
const {
|
const {
|
||||||
inject = null,
|
inject = null,
|
||||||
@@ -4134,7 +4147,7 @@ async function ensureContentScriptReadyOnTabUntilStopped(source, tabId, options
|
|||||||
while (true) {
|
while (true) {
|
||||||
throwIfStopped();
|
throwIfStopped();
|
||||||
const pong = await pingContentScriptOnTab(tabId);
|
const pong = await pingContentScriptOnTab(tabId);
|
||||||
if (pong?.ok && (!pong.source || pong.source === source)) {
|
if (isContentScriptReadyPong(source, pong)) {
|
||||||
await registerTab(source, tabId);
|
await registerTab(source, tabId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -4159,10 +4172,13 @@ async function ensureContentScriptReadyOnTabUntilStopped(source, tabId, options
|
|||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(LOG_PREFIX, `[ensureContentScriptReadyOnTabUntilStopped] inject failed for ${source}:`, error?.message || error);
|
console.warn(LOG_PREFIX, `[ensureContentScriptReadyOnTabUntilStopped] inject failed for ${source}:`, error?.message || error);
|
||||||
|
if (isUnrecoverableContentScriptInjectError(error)) {
|
||||||
|
throw new Error(`${getSourceLabel(source)} 内容脚本文件加载失败:${error?.message || error}。请在扩展管理页重新加载当前扩展,确认文件已包含在已加载的扩展目录中。`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const pongAfterInject = await pingContentScriptOnTab(tabId);
|
const pongAfterInject = await pingContentScriptOnTab(tabId);
|
||||||
if (pongAfterInject?.ok && (!pongAfterInject.source || pongAfterInject.source === source)) {
|
if (isContentScriptReadyPong(source, pongAfterInject)) {
|
||||||
await registerTab(source, tabId);
|
await registerTab(source, tabId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,6 @@
|
|||||||
async function executePlusCheckoutCreate() {
|
async function executePlusCheckoutCreate() {
|
||||||
await addLog('步骤 6:正在打开 ChatGPT 会话页,准备创建 Plus Checkout...', 'info');
|
await addLog('步骤 6:正在打开 ChatGPT 会话页,准备创建 Plus Checkout...', 'info');
|
||||||
const tabId = await reuseOrCreateTab(PLUS_CHECKOUT_SOURCE, PLUS_CHECKOUT_ENTRY_URL, {
|
const tabId = await reuseOrCreateTab(PLUS_CHECKOUT_SOURCE, PLUS_CHECKOUT_ENTRY_URL, {
|
||||||
inject: PLUS_CHECKOUT_INJECT_FILES,
|
|
||||||
injectSource: PLUS_CHECKOUT_SOURCE,
|
|
||||||
reloadIfSameUrl: false,
|
reloadIfSameUrl: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// content/plus-checkout.js — ChatGPT Plus checkout helper.
|
// content/plus-checkout.js — ChatGPT Plus checkout helper.
|
||||||
|
|
||||||
console.log('[MultiPage:plus-checkout] Content script loaded on', location.href);
|
console.log('[MultiPage:plus-checkout] Content script loaded on', location.href);
|
||||||
|
window.__MULTIPAGE_PLUS_CHECKOUT_READY__ = true;
|
||||||
|
|
||||||
const PLUS_CHECKOUT_LISTENER_SENTINEL = 'data-multipage-plus-checkout-listener';
|
const PLUS_CHECKOUT_LISTENER_SENTINEL = 'data-multipage-plus-checkout-listener';
|
||||||
const PLUS_CHECKOUT_PAYLOAD = {
|
const PLUS_CHECKOUT_PAYLOAD = {
|
||||||
|
|||||||
+11
-6
@@ -34,6 +34,10 @@ const SCRIPT_SOURCE = (() => {
|
|||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
function getRuntimeScriptSource() {
|
||||||
|
return window.__MULTIPAGE_SOURCE || SCRIPT_SOURCE;
|
||||||
|
}
|
||||||
|
|
||||||
const LOG_PREFIX = `[MultiPage:${SCRIPT_SOURCE}]`;
|
const LOG_PREFIX = `[MultiPage:${SCRIPT_SOURCE}]`;
|
||||||
const STOP_ERROR_MESSAGE = '流程已被用户停止。';
|
const STOP_ERROR_MESSAGE = '流程已被用户停止。';
|
||||||
let flowStopped = false;
|
let flowStopped = false;
|
||||||
@@ -51,7 +55,8 @@ if (!window.__MULTIPAGE_UTILS_LISTENER_READY__) {
|
|||||||
if (message.type === 'PING') {
|
if (message.type === 'PING') {
|
||||||
sendResponse({
|
sendResponse({
|
||||||
ok: true,
|
ok: true,
|
||||||
source: SCRIPT_SOURCE,
|
source: getRuntimeScriptSource(),
|
||||||
|
plusCheckoutReady: Boolean(window.__MULTIPAGE_PLUS_CHECKOUT_READY__),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -265,7 +270,7 @@ function fillSelect(el, value) {
|
|||||||
function log(message, level = 'info') {
|
function log(message, level = 'info') {
|
||||||
chrome.runtime.sendMessage({
|
chrome.runtime.sendMessage({
|
||||||
type: 'LOG',
|
type: 'LOG',
|
||||||
source: SCRIPT_SOURCE,
|
source: getRuntimeScriptSource(),
|
||||||
step: null,
|
step: null,
|
||||||
payload: { message, level, timestamp: Date.now() },
|
payload: { message, level, timestamp: Date.now() },
|
||||||
error: null,
|
error: null,
|
||||||
@@ -279,7 +284,7 @@ function reportReady() {
|
|||||||
console.log(LOG_PREFIX, '内容脚本已就绪');
|
console.log(LOG_PREFIX, '内容脚本已就绪');
|
||||||
const message = {
|
const message = {
|
||||||
type: 'CONTENT_SCRIPT_READY',
|
type: 'CONTENT_SCRIPT_READY',
|
||||||
source: SCRIPT_SOURCE,
|
source: getRuntimeScriptSource(),
|
||||||
step: null,
|
step: null,
|
||||||
payload: {},
|
payload: {},
|
||||||
error: null,
|
error: null,
|
||||||
@@ -303,7 +308,7 @@ function reportComplete(step, data = {}) {
|
|||||||
log(`步骤 ${step} 已成功完成`, 'ok');
|
log(`步骤 ${step} 已成功完成`, 'ok');
|
||||||
const message = {
|
const message = {
|
||||||
type: 'STEP_COMPLETE',
|
type: 'STEP_COMPLETE',
|
||||||
source: SCRIPT_SOURCE,
|
source: getRuntimeScriptSource(),
|
||||||
step,
|
step,
|
||||||
payload: data,
|
payload: data,
|
||||||
error: null,
|
error: null,
|
||||||
@@ -334,7 +339,7 @@ function reportError(step, errorMessage) {
|
|||||||
log(`步骤 ${step} 失败:${errorMessage}`, 'error');
|
log(`步骤 ${step} 失败:${errorMessage}`, 'error');
|
||||||
const message = {
|
const message = {
|
||||||
type: 'STEP_ERROR',
|
type: 'STEP_ERROR',
|
||||||
source: SCRIPT_SOURCE,
|
source: getRuntimeScriptSource(),
|
||||||
step,
|
step,
|
||||||
payload: {},
|
payload: {},
|
||||||
error: errorMessage,
|
error: errorMessage,
|
||||||
@@ -435,6 +440,6 @@ function shouldReportReadyForFrame(source, isChildFrame) {
|
|||||||
|
|
||||||
// Auto-report ready on load. Child frames are probed explicitly by frameId, so
|
// Auto-report ready on load. Child frames are probed explicitly by frameId, so
|
||||||
// they should not overwrite the tab-level registration or spam the side panel.
|
// they should not overwrite the tab-level registration or spam the side panel.
|
||||||
if (shouldReportReadyForFrame(SCRIPT_SOURCE, window !== window.top)) {
|
if (shouldReportReadyForFrame(getRuntimeScriptSource(), window !== window.top)) {
|
||||||
reportReady();
|
reportReady();
|
||||||
}
|
}
|
||||||
|
|||||||
+122
-118
@@ -1,127 +1,131 @@
|
|||||||
const HOTMAIL_PROVIDER = 'hotmail-api';
|
(function attachMailProviderUtils(root, factory) {
|
||||||
const GMAIL_PROVIDER = 'gmail';
|
const api = factory();
|
||||||
const NETEASE_LIST_PATH = '/js6/main.jsp?df=mail163_letter#module=mbox.ListModule%7C%7B%22fid%22%3A1%2C%22order%22%3A%22date%22%2C%22desc%22%3Atrue%7D';
|
|
||||||
const ICLOUD_TARGET_MAILBOX_TYPE_INBOX = 'icloud-inbox';
|
|
||||||
const ICLOUD_TARGET_MAILBOX_TYPE_FORWARD = 'forward-mailbox';
|
|
||||||
const ICLOUD_FORWARD_MAIL_PROVIDER_OPTIONS = [
|
|
||||||
{ value: 'qq', label: 'QQ 邮箱' },
|
|
||||||
{ value: '163', label: '163 邮箱' },
|
|
||||||
{ value: '163-vip', label: '163 VIP 邮箱' },
|
|
||||||
{ value: '126', label: '126 邮箱' },
|
|
||||||
{ value: GMAIL_PROVIDER, label: 'Gmail 邮箱' },
|
|
||||||
];
|
|
||||||
|
|
||||||
function normalizeMailProvider(value = '') {
|
if (typeof module !== 'undefined' && module.exports) {
|
||||||
const normalized = String(value || '').trim().toLowerCase();
|
module.exports = api;
|
||||||
switch (normalized) {
|
|
||||||
case HOTMAIL_PROVIDER:
|
|
||||||
case '163':
|
|
||||||
case '163-vip':
|
|
||||||
case '126':
|
|
||||||
case 'qq':
|
|
||||||
case 'inbucket':
|
|
||||||
return normalized;
|
|
||||||
default:
|
|
||||||
return '163';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeIcloudTargetMailboxType(value = '') {
|
|
||||||
return String(value || '').trim().toLowerCase() === ICLOUD_TARGET_MAILBOX_TYPE_FORWARD
|
|
||||||
? ICLOUD_TARGET_MAILBOX_TYPE_FORWARD
|
|
||||||
: ICLOUD_TARGET_MAILBOX_TYPE_INBOX;
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeIcloudForwardMailProvider(value = '') {
|
|
||||||
const normalized = String(value || '').trim().toLowerCase();
|
|
||||||
return ICLOUD_FORWARD_MAIL_PROVIDER_OPTIONS.some((option) => option.value === normalized)
|
|
||||||
? normalized
|
|
||||||
: 'qq';
|
|
||||||
}
|
|
||||||
|
|
||||||
function getIcloudForwardMailProviderOptions() {
|
|
||||||
return ICLOUD_FORWARD_MAIL_PROVIDER_OPTIONS.map((option) => ({ ...option }));
|
|
||||||
}
|
|
||||||
|
|
||||||
function getIcloudForwardMailConfig(provider = 'qq') {
|
|
||||||
const normalizedProvider = normalizeIcloudForwardMailProvider(provider);
|
|
||||||
if (normalizedProvider === GMAIL_PROVIDER) {
|
|
||||||
return {
|
|
||||||
source: 'gmail-mail',
|
|
||||||
url: 'https://mail.google.com/mail/u/0/#inbox',
|
|
||||||
label: 'Gmail 邮箱',
|
|
||||||
inject: ['content/activation-utils.js', 'content/utils.js', 'content/gmail-mail.js'],
|
|
||||||
injectSource: 'gmail-mail',
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return getMailProviderConfig({ mailProvider: normalizedProvider });
|
if (root) {
|
||||||
}
|
root.MailProviderUtils = api;
|
||||||
|
}
|
||||||
|
})(typeof self !== 'undefined' ? self : globalThis, function createMailProviderUtils() {
|
||||||
|
const HOTMAIL_PROVIDER = 'hotmail-api';
|
||||||
|
const GMAIL_PROVIDER = 'gmail';
|
||||||
|
const NETEASE_LIST_PATH = '/js6/main.jsp?df=mail163_letter#module=mbox.ListModule%7C%7B%22fid%22%3A1%2C%22order%22%3A%22date%22%2C%22desc%22%3Atrue%7D';
|
||||||
|
const ICLOUD_TARGET_MAILBOX_TYPE_INBOX = 'icloud-inbox';
|
||||||
|
const ICLOUD_TARGET_MAILBOX_TYPE_FORWARD = 'forward-mailbox';
|
||||||
|
const ICLOUD_FORWARD_MAIL_PROVIDER_OPTIONS = [
|
||||||
|
{ value: 'qq', label: 'QQ 邮箱' },
|
||||||
|
{ value: '163', label: '163 邮箱' },
|
||||||
|
{ value: '163-vip', label: '163 VIP 邮箱' },
|
||||||
|
{ value: '126', label: '126 邮箱' },
|
||||||
|
{ value: GMAIL_PROVIDER, label: 'Gmail 邮箱' },
|
||||||
|
];
|
||||||
|
|
||||||
function getMailProviderConfig(state = {}, options = {}) {
|
function normalizeMailProvider(value = '') {
|
||||||
const provider = normalizeMailProvider(state.mailProvider);
|
const normalized = String(value || '').trim().toLowerCase();
|
||||||
const normalizeInbucketOrigin = options.normalizeInbucketOrigin || (() => '');
|
switch (normalized) {
|
||||||
|
case HOTMAIL_PROVIDER:
|
||||||
if (provider === HOTMAIL_PROVIDER) {
|
case '163':
|
||||||
return { provider: HOTMAIL_PROVIDER, label: 'Hotmail(微软 Graph)' };
|
case '163-vip':
|
||||||
}
|
case '126':
|
||||||
if (provider === '163') {
|
case 'qq':
|
||||||
return {
|
case 'inbucket':
|
||||||
source: 'mail-163',
|
return normalized;
|
||||||
url: `https://mail.163.com${NETEASE_LIST_PATH}`,
|
default:
|
||||||
label: '163 邮箱',
|
return '163';
|
||||||
};
|
|
||||||
}
|
|
||||||
if (provider === '163-vip') {
|
|
||||||
return {
|
|
||||||
source: 'mail-163',
|
|
||||||
url: `https://webmail.vip.163.com${NETEASE_LIST_PATH}`,
|
|
||||||
label: '163 VIP 邮箱',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (provider === '126') {
|
|
||||||
return {
|
|
||||||
source: 'mail-163',
|
|
||||||
url: `https://mail.126.com${NETEASE_LIST_PATH}`,
|
|
||||||
label: '126 邮箱',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (provider === 'inbucket') {
|
|
||||||
const host = normalizeInbucketOrigin(state.inbucketHost);
|
|
||||||
const mailbox = String(state.inbucketMailbox || '').trim();
|
|
||||||
if (!host) {
|
|
||||||
return { error: 'Inbucket 主机地址为空或无效。' };
|
|
||||||
}
|
}
|
||||||
if (!mailbox) {
|
|
||||||
return { error: 'Inbucket 邮箱名称为空。' };
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
source: 'inbucket-mail',
|
|
||||||
url: `${host}/m/${encodeURIComponent(mailbox)}/`,
|
|
||||||
label: `Inbucket 邮箱(${mailbox})`,
|
|
||||||
navigateOnReuse: true,
|
|
||||||
inject: ['content/activation-utils.js', 'content/utils.js', 'content/inbucket-mail.js'],
|
|
||||||
injectSource: 'inbucket-mail',
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return { source: 'qq-mail', url: 'https://wx.mail.qq.com/', label: 'QQ 邮箱' };
|
|
||||||
}
|
|
||||||
|
|
||||||
const api = {
|
function normalizeIcloudTargetMailboxType(value = '') {
|
||||||
GMAIL_PROVIDER,
|
return String(value || '').trim().toLowerCase() === ICLOUD_TARGET_MAILBOX_TYPE_FORWARD
|
||||||
HOTMAIL_PROVIDER,
|
? ICLOUD_TARGET_MAILBOX_TYPE_FORWARD
|
||||||
getIcloudForwardMailConfig,
|
: ICLOUD_TARGET_MAILBOX_TYPE_INBOX;
|
||||||
getIcloudForwardMailProviderOptions,
|
}
|
||||||
getMailProviderConfig,
|
|
||||||
normalizeIcloudForwardMailProvider,
|
|
||||||
normalizeIcloudTargetMailboxType,
|
|
||||||
normalizeMailProvider,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (typeof module !== 'undefined' && module.exports) {
|
function normalizeIcloudForwardMailProvider(value = '') {
|
||||||
module.exports = api;
|
const normalized = String(value || '').trim().toLowerCase();
|
||||||
}
|
return ICLOUD_FORWARD_MAIL_PROVIDER_OPTIONS.some((option) => option.value === normalized)
|
||||||
|
? normalized
|
||||||
|
: 'qq';
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof self !== 'undefined') {
|
function getIcloudForwardMailProviderOptions() {
|
||||||
self.MailProviderUtils = api;
|
return ICLOUD_FORWARD_MAIL_PROVIDER_OPTIONS.map((option) => ({ ...option }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getIcloudForwardMailConfig(provider = 'qq') {
|
||||||
|
const normalizedProvider = normalizeIcloudForwardMailProvider(provider);
|
||||||
|
if (normalizedProvider === GMAIL_PROVIDER) {
|
||||||
|
return {
|
||||||
|
source: 'gmail-mail',
|
||||||
|
url: 'https://mail.google.com/mail/u/0/#inbox',
|
||||||
|
label: 'Gmail 邮箱',
|
||||||
|
inject: ['content/activation-utils.js', 'content/utils.js', 'content/gmail-mail.js'],
|
||||||
|
injectSource: 'gmail-mail',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return getMailProviderConfig({ mailProvider: normalizedProvider });
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMailProviderConfig(state = {}, options = {}) {
|
||||||
|
const provider = normalizeMailProvider(state.mailProvider);
|
||||||
|
const normalizeInbucketOrigin = options.normalizeInbucketOrigin || (() => '');
|
||||||
|
|
||||||
|
if (provider === HOTMAIL_PROVIDER) {
|
||||||
|
return { provider: HOTMAIL_PROVIDER, label: 'Hotmail(微软 Graph)' };
|
||||||
|
}
|
||||||
|
if (provider === '163') {
|
||||||
|
return {
|
||||||
|
source: 'mail-163',
|
||||||
|
url: `https://mail.163.com${NETEASE_LIST_PATH}`,
|
||||||
|
label: '163 邮箱',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (provider === '163-vip') {
|
||||||
|
return {
|
||||||
|
source: 'mail-163',
|
||||||
|
url: `https://webmail.vip.163.com${NETEASE_LIST_PATH}`,
|
||||||
|
label: '163 VIP 邮箱',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (provider === '126') {
|
||||||
|
return {
|
||||||
|
source: 'mail-163',
|
||||||
|
url: `https://mail.126.com${NETEASE_LIST_PATH}`,
|
||||||
|
label: '126 邮箱',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (provider === 'inbucket') {
|
||||||
|
const host = normalizeInbucketOrigin(state.inbucketHost);
|
||||||
|
const mailbox = String(state.inbucketMailbox || '').trim();
|
||||||
|
if (!host) {
|
||||||
|
return { error: 'Inbucket 主机地址为空或无效。' };
|
||||||
|
}
|
||||||
|
if (!mailbox) {
|
||||||
|
return { error: 'Inbucket 邮箱名称为空。' };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
source: 'inbucket-mail',
|
||||||
|
url: `${host}/m/${encodeURIComponent(mailbox)}/`,
|
||||||
|
label: `Inbucket 邮箱(${mailbox})`,
|
||||||
|
navigateOnReuse: true,
|
||||||
|
inject: ['content/activation-utils.js', 'content/utils.js', 'content/inbucket-mail.js'],
|
||||||
|
injectSource: 'inbucket-mail',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { source: 'qq-mail', url: 'https://wx.mail.qq.com/', label: 'QQ 邮箱' };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
GMAIL_PROVIDER,
|
||||||
|
HOTMAIL_PROVIDER,
|
||||||
|
getIcloudForwardMailConfig,
|
||||||
|
getIcloudForwardMailProviderOptions,
|
||||||
|
getMailProviderConfig,
|
||||||
|
normalizeIcloudForwardMailProvider,
|
||||||
|
normalizeIcloudTargetMailboxType,
|
||||||
|
normalizeMailProvider,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|||||||
@@ -92,3 +92,16 @@ return { shouldReportReadyForFrame };
|
|||||||
assert.equal(api.shouldReportReadyForFrame('plus-checkout', false), true);
|
assert.equal(api.shouldReportReadyForFrame('plus-checkout', false), true);
|
||||||
assert.equal(api.shouldReportReadyForFrame('paypal-flow', true), 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');
|
||||||
|
});
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ test('Plus checkout create does not wait 20 seconds after opening checkout page'
|
|||||||
ensureContentScriptReadyOnTabUntilStopped: async () => {
|
ensureContentScriptReadyOnTabUntilStopped: async () => {
|
||||||
events.push({ type: 'ready' });
|
events.push({ type: 'ready' });
|
||||||
},
|
},
|
||||||
reuseOrCreateTab: async () => 42,
|
reuseOrCreateTab: async (source, url, options) => {
|
||||||
|
events.push({ type: 'reuse-tab', source, url, options });
|
||||||
|
return 42;
|
||||||
|
},
|
||||||
sendTabMessageUntilStopped: async () => ({
|
sendTabMessageUntilStopped: async () => ({
|
||||||
checkoutUrl: 'https://checkout.stripe.com/c/pay/session',
|
checkoutUrl: 'https://checkout.stripe.com/c/pay/session',
|
||||||
country: 'US',
|
country: 'US',
|
||||||
@@ -44,6 +47,11 @@ test('Plus checkout create does not wait 20 seconds after opening checkout page'
|
|||||||
|
|
||||||
await executor.executePlusCheckoutCreate();
|
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');
|
const sleepEvents = events.filter((event) => event.type === 'sleep');
|
||||||
assert.deepStrictEqual(sleepEvents.map((event) => event.ms), [1000, 1000]);
|
assert.deepStrictEqual(sleepEvents.map((event) => event.ms), [1000, 1000]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user