我想要创建一个Safari网页扩展程序与我的本地应用进行交互。我希望可以弹出一个按钮,当点击时可以与我的本地应用通信:
browser.runtime.sendNativeMessage({message: "Open Main App"}, function(response) {
console.log("Received sendNativeMessage response:");
console.log(response);
});
然而,该应用程序无法接收来自Safari Web扩展程序发送的消息:
func beginRequest(with context: NSExtensionContext) {
its the function that handles all things
then
if msg.contains("Open Main App") == true {
print("NEED TO OPEN")
guard let url = URL(string: "player:Vacation?index=1") else {
return
}
NSWorkspace.shared.open(url)
}
Safari浏览器日志显示以下错误信息:
ReferenceError: Can't find variable: browser
出了什么问题?