1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-23 11:56:00 +01:00

content script messaging for safari app

This commit is contained in:
Kyle Spearrin 2019-08-15 20:14:51 -04:00
parent 98ac83dbc1
commit 53cc6f0a2b
2 changed files with 9 additions and 2 deletions

View File

@ -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) {

View File

@ -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);
});
});