feat: 增强内容脚本的加载机制,添加超时与重试逻辑,优化消息监听器的初始化
This commit is contained in:
+17
-13
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user