feat: 增强内容脚本与后台通信,添加 PING 响应和确保脚本就绪的机制

This commit is contained in:
QLHazyCoder
2026-04-11 02:01:36 +08:00
parent bac7113c0c
commit 359566131d
3 changed files with 102 additions and 41 deletions
+9 -1
View File
@@ -17,10 +17,18 @@ const LOG_PREFIX = `[MultiPage:${SCRIPT_SOURCE}]`;
const STOP_ERROR_MESSAGE = '流程已被用户停止。';
let flowStopped = false;
chrome.runtime.onMessage.addListener((message) => {
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,
});
}
});