feat: 增强内容脚本的加载机制,添加超时与重试逻辑,优化消息监听器的初始化

This commit is contained in:
QLHazyCoder
2026-04-11 02:52:55 +08:00
parent f034248d49
commit c14266ee4d
2 changed files with 107 additions and 55 deletions
+17 -13
View File
@@ -17,20 +17,24 @@ const LOG_PREFIX = `[MultiPage:${SCRIPT_SOURCE}]`;
const STOP_ERROR_MESSAGE = '流程已被用户停止。';
let flowStopped = false;
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'STOP_FLOW') {
flowStopped = true;
console.warn(LOG_PREFIX, STOP_ERROR_MESSAGE);
return;
}
if (!window.__MULTIPAGE_UTILS_LISTENER_READY__) {
window.__MULTIPAGE_UTILS_LISTENER_READY__ = true;
if (message.type === 'PING') {
sendResponse({
ok: true,
source: SCRIPT_SOURCE,
});
}
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'STOP_FLOW') {
flowStopped = true;
console.warn(LOG_PREFIX, STOP_ERROR_MESSAGE);
return;
}
if (message.type === 'PING') {
sendResponse({
ok: true,
source: SCRIPT_SOURCE,
});
}
});
}
function resetStopState() {
flowStopped = false;