I'm trying to create a Safari Web Extension to my native app. I want to have a popup with a button which when clicked will communicate with my native app. Before I get to this part I have a problem sending a native message and handling it in beginRequest
function from class conforming to the NSExtensionRequestHandling
protocol. I didn't do much because I'm relying on the code generated by Xcode.
in manifest.json
I added nativeMessaging
permission like that:
"permissions": [ "nativeMessaging" ]
popup.js
which contains event listener:
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)
When I inspect the popup element I can see Hello World
and click
message but as I mentioned before - beginRequest
is not called. Is there anything missing?
I also watched Meet Safari Web Extensions
session from WWDC20 but I didn't find an answer.