我正在尝试为我的本机应用程序创建 Safari Web 扩展。我想要一个带有按钮的弹出窗口,单击该按钮将与我的本机应用程序进行通信。在开始这部分之前,我在发送本机消息并在beginRequest符合NSExtensionRequestHandling协议的类的函数中处理它时遇到了问题。我没有做太多事情,因为我依赖于 Xcode 生成的代码。
manifest.json我添加了这样nativeMessaging的权限:
"permissions": [ "nativeMessaging" ]
Run Code Online (Sandbox Code Playgroud)
popup.js其中包含事件监听器:
console.log("Hello World!", browser);
document.addEventListener('DOMContentLoaded', function() {
var checkPageButton = document.getElementById('clickIt');
checkPageButton.addEventListener('click', function() {
console.log("click")
browser.runtime.sendNativeMessage({ message: "Hello" });
}, false)
}, false)
Run Code Online (Sandbox Code Playgroud)
当我检查弹出元素时,我可以看到消息Hello World并显示click消息,但正如我之前提到的 -beginRequest没有被调用。有什么遗漏吗?我也观看了WWDC20 的Meet Safari Web Extensions 会议,但没有找到答案。
javascript safari-extension safariservices safari-web-extension