diff --git a/src/browser/safariApp.ts b/src/browser/safariApp.ts index ac7721936a..4582ed63cc 100644 --- a/src/browser/safariApp.ts +++ b/src/browser/safariApp.ts @@ -42,10 +42,10 @@ export class SafariApp { if (message == null) { return; } - if ((message.id == null || message.id === '') && message.command === 'cs_message') { + if ((message.id == null || message.id === '') && message.command === 'app_message') { try { const msg = JSON.parse(message.data); - SafariApp.sendMessageToListeners(msg, 'cs_message', null); + SafariApp.sendMessageToListeners(msg, 'app_message', null); } catch { } } else if (message.id != null && (window as any).bitwardenSafariAppRequests.has(message.id)) { const p = (window as any).bitwardenSafariAppRequests.get(message.id); diff --git a/src/popup/app.component.ts b/src/popup/app.component.ts index ae9e77671c..1a1f0521d1 100644 --- a/src/popup/app.component.ts +++ b/src/popup/app.component.ts @@ -127,6 +127,8 @@ export class AppComponent implements OnInit { // Wait to make sure background has reloaded first. window.setTimeout(() => BrowserApi.reloadExtension(window), 2000); } + } else if (msg.command === 'reloadPopup') { + this.router.navigate(['/']); } else { msg.webExtSender = sender; this.broadcasterService.send(msg); diff --git a/src/safari/app/desktop/safari/SafariExtensionHandler.swift b/src/safari/app/desktop/safari/SafariExtensionHandler.swift index ae2acd8b31..9d6c1d8b7e 100644 --- a/src/safari/app/desktop/safari/SafariExtensionHandler.swift +++ b/src/safari/app/desktop/safari/SafariExtensionHandler.swift @@ -16,7 +16,7 @@ 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 ?? [:]))") DispatchQueue.main.async { - SafariExtensionViewController.shared.replyMessageFromScript(msg: userInfo) + SafariExtensionViewController.shared.sendMessage(msg: userInfo) } } } @@ -35,5 +35,11 @@ class SafariExtensionHandler: SFSafariExtensionHandler { override func popoverViewController() -> SFSafariExtensionViewController { return SafariExtensionViewController.shared } + + override func popoverWillShow(in window: SFSafariWindow) { + DispatchQueue.main.async { + SafariExtensionViewController.shared.sendMessage(msg: ["command": "reloadPopup"]) + } + } } diff --git a/src/safari/app/desktop/safari/SafariExtensionViewController.swift b/src/safari/app/desktop/safari/SafariExtensionViewController.swift index 9c2e9ebfbb..a8745014b1 100644 --- a/src/safari/app/desktop/safari/SafariExtensionViewController.swift +++ b/src/safari/app/desktop/safari/SafariExtensionViewController.swift @@ -153,12 +153,12 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe webView.evaluateJavaScript("window.bitwardenSafariAppMessageReceiver(\(json));", completionHandler: nil) } - func replyMessageFromScript(msg: [String : Any]?) { + func sendMessage(msg: [String : Any]?) { if(webView == nil) { return; } let newMsg = AppMessage() - newMsg.command = "cs_message" + newMsg.command = "app_message" do { let jsonData = try JSONSerialization.data(withJSONObject: msg as Any, options: []) newMsg.data = String(data: jsonData, encoding: .utf8)