Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法等到接收方处理使用发送的消息port.postMessage(message)?我希望像回调这样的东西作为第二个参数传递,类似于chrome.scripting.executeScript(injection, callback)
port.postMessage(message)
chrome.scripting.executeScript(injection, callback)
据我所知,不是本地的,但包装器很容易实现。您需要一个将为每条消息生成随机 UID(唯一 ID)并存储 map 的类{ [uid]: cb }。将生成的 UID 附加到消息中。响应还需要包含相同的 UID。
{ [uid]: cb }