diff --git a/src/safari/app/desktop/safari/SafariExtensionHandler.swift b/src/safari/app/desktop/safari/SafariExtensionHandler.swift index 1bc2960eae..efb8e099d8 100644 --- a/src/safari/app/desktop/safari/SafariExtensionHandler.swift +++ b/src/safari/app/desktop/safari/SafariExtensionHandler.swift @@ -15,6 +15,8 @@ class SafariExtensionHandler: SFSafariExtensionHandler { page.getPropertiesWithCompletionHandler { properties in NSLog("The extension received a message (\(messageName)) from a script injected into (\(String(describing: properties?.url))) with userInfo (\(userInfo ?? [:]))") } + + page.dispatchMessageToScript(withName: "getInfo", userInfo: ["hello": "world", "foo": "bar"]) } override func toolbarItemClicked(in window: SFSafariWindow) { diff --git a/src/safari/app/desktop/safari/script.js b/src/safari/app/desktop/safari/script.js index 34f7e3550e..0bd8816292 100644 --- a/src/safari/app/desktop/safari/script.js +++ b/src/safari/app/desktop/safari/script.js @@ -1,3 +1,8 @@ -document.addEventListener("DOMContentLoaded", function(event) { - safari.extension.dispatchMessage("Hello World!"); +document.addEventListener("DOMContentLoaded", (event) => { + safari.extension.dispatchMessage("Hello World!", { key: "value2" }); + + safari.self.addEventListener("message", (e) => { + console.log(e); + + }); });