From 9b9513fea575930e75af00bd9ca45157d47a0137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=80=E4=B9=8B?= Date: Wed, 12 Feb 2025 22:27:43 +0800 Subject: [PATCH] a --- src/app/service/service_worker/index.ts | 24 +----------------------- src/types/main.d.ts | 2 +- tsconfig.json | 3 ++- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/app/service/service_worker/index.ts b/src/app/service/service_worker/index.ts index 1ad59b3..78738a3 100644 --- a/src/app/service/service_worker/index.ts +++ b/src/app/service/service_worker/index.ts @@ -22,29 +22,7 @@ export default class ServiceWorkerManager { // 准备好环境 this.mq.emit("preparationOffscreen", {}); - const ctx = await chrome.runtime.getContexts({ - contextTypes: [chrome.runtime.ContextType.OFFSCREEN_DOCUMENT], - documentUrls: [chrome.runtime.getURL("src/offscreen.html")], - }); - console.log("ctx", ctx, chrome.runtime.getURL("src/offscreen.html")); - chrome.scripting.executeScript({ - target: { - documentIds: [ctx[0]!.documentId!], - tabId: -1, - }, - func: (message) => { - // 在页面上下文中执行的代码 - console.log("tesss"); - window.postMessage( - { - type: "sendMessage", - daat: message, - }, - "*" - ); - }, - args: [{ action: "test", data: "test" }], - }); + // sendMessageToOffscreen("preparationOffscreen", {}); }); const resource = new ResourceService(group.group("resource"), this.mq); diff --git a/src/types/main.d.ts b/src/types/main.d.ts index 279e754..2054099 100644 --- a/src/types/main.d.ts +++ b/src/types/main.d.ts @@ -5,7 +5,7 @@ declare module "*.yaml"; declare const sandbox: Window; -declare const clients: Clients; +declare const self: ServiceWorkerGlobalScope; declare namespace GMSend { interface XHRDetails { diff --git a/tsconfig.json b/tsconfig.json index bc2628d..cdf0b66 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,8 @@ "target": "ES2020", "lib": [ "DOM", - "ES2020" + "ES2020", + "WebWorker" ], "module": "ESNext", "jsx": "react-jsx",