From 5c1deab61e24b25897ed5d5c71d8b8644320441a Mon Sep 17 00:00:00 2001 From: longnk Date: Mon, 18 Aug 2025 18:36:45 +0800 Subject: [PATCH] Update background.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复浏览器重启后无法接收消息的问题 --- background.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/background.js b/background.js index 917ac81..130d299 100644 --- a/background.js +++ b/background.js @@ -5,6 +5,18 @@ import './js/save-utils.js'; consoleLog('开始执行background.js Service Worker'); +chrome.runtime.onStartup.addListener(async () => { + consoleLog('等待初始化...'); + // 初始化应用 + new Promise(resolve => { + chrome.storage.local.get(null, (items) => { + consoleLog('初始化完成'); + init(); + resolve(); + }); + }); +}); + // 监听Service Worker的安装事件 self.addEventListener('install', (event) => { consoleLog('Service Worker 安装中...'); @@ -85,4 +97,5 @@ function initOrUpdatePushToken(wsInitMsg) { return; } //如果没有uid,需要用户点开扩展弹出页面,扫码登陆 -} \ No newline at end of file + +}