content script messaging for safari app
This commit is contained in:
parent
98ac83dbc1
commit
53cc6f0a2b
|
@ -15,6 +15,8 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
|
||||||
page.getPropertiesWithCompletionHandler { properties in
|
page.getPropertiesWithCompletionHandler { properties in
|
||||||
NSLog("The extension received a message (\(messageName)) from a script injected into (\(String(describing: properties?.url))) with userInfo (\(userInfo ?? [:]))")
|
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) {
|
override func toolbarItemClicked(in window: SFSafariWindow) {
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
document.addEventListener("DOMContentLoaded", function(event) {
|
document.addEventListener("DOMContentLoaded", (event) => {
|
||||||
safari.extension.dispatchMessage("Hello World!");
|
safari.extension.dispatchMessage("Hello World!", { key: "value2" });
|
||||||
|
|
||||||
|
safari.self.addEventListener("message", (e) => {
|
||||||
|
console.log(e);
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue