王一之 57bef5a023
Some checks failed
test / Run tests (push) Failing after 15s
build / Build (push) Failing after 19s
调整通信
2025-03-22 02:50:56 +08:00

17 lines
964 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 消息
对扩展内消息交互的抽象
主要会有以下几种类型的消息:
- 从脚本发起的GM请求需要层层传递到service_worker/offscreen进行处理有的GM只需要进行一次调用获取一次结果有的需要进行
多次调用获取多次结果使用connect的方式实现
- 从service_worker/offscreen发起的请求类似消息队列其它页面进行监听触发后广播给所有页面使用sendMessage方式实现
- 从扩展页面发起的请求需要传递到service_worker/offscreen进行处理如果只是单次调用获取一次结果使用sendMessage方式实现如果需要
多次调用获取多次结果使用connect方式实现
## 注意点
- service_worker和offscreen之间可以使用postMessage的方式进行通信避免同时监听message与connect导致冲突的问题
- service_worker会变为不活动的状态尽量避免与service_worker建立长连接