aa
Some checks failed
test / Run tests (push) Failing after 11s
build / Build (push) Failing after 16s

This commit is contained in:
2025-02-12 23:12:03 +08:00
parent 3a41bf0f21
commit fcf9f6fd63
3 changed files with 4 additions and 8 deletions

View File

@ -87,12 +87,11 @@ export default class GMApi {
}
}
export async function sendMessageToOffscreen(action: string, data?: any) {
// service_worker和offscreen同时监听消息,会导致消息被两边同时接收,但是返回结果时会产生问题,导致报错
// 不进行监听的话又无法从service_worker主动发送消息
// 所以这里通过clients.matchAll()获取到所有的client,然后通过postMessage发送消息
const list = await clients.matchAll();
const list = await clients.matchAll({ includeUncontrolled: true, type: "window" });
list[0].postMessage({
type: "sendMessage",
data: { action, data },