Safari 网页扩展无法发送本地消息。

4

我想要创建一个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

出了什么问题?


1
我也遇到了这个问题。你找到解决方案了吗? - Matteo
1个回答

1

您是否在后台脚本中使用了 browser.runtime.sendNativeMessage? 您还需要在清单文件中设置权限。 如下所示:"permissions": [ "nativeMessaging" ]


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接