Reputation: 1187
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:
browser.runtime.sendNativeMessage({message: "Open Main App"}, function(response) {
console.log("Received sendNativeMessage response:");
console.log(response);
});
However, the app fails to receive the message sent from the Safari Web Extension:
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 log showed this error message:
ReferenceError: Can't find variable: browser
What is wrong?
Upvotes: 4
Views: 732
Reputation: 98
Did you use browser.runtime.sendNativeMessage
from the background script?
You also need to set the permission in the manifest file.
Like so: "permissions": [ "nativeMessaging" ]
Upvotes: 2