diff --git a/src/safari/app/desktop/safari/SafariExtensionHandler.swift b/src/safari/app/desktop/safari/SafariExtensionHandler.swift index 7b7b0c8469..142166c47c 100644 --- a/src/safari/app/desktop/safari/SafariExtensionHandler.swift +++ b/src/safari/app/desktop/safari/SafariExtensionHandler.swift @@ -9,6 +9,11 @@ import SafariServices class SafariExtensionHandler: SFSafariExtensionHandler { + override init() { + super.init() + SafariExtensionViewController.shared.initWebView() + } + override func messageReceived(withName messageName: String, from page: SFSafariPage, userInfo: [String: Any]?) { // This method will be called when a content script provided by your extension calls safari.extension.dispatchMessage("message"). if messageName == "bitwarden" { diff --git a/src/safari/app/desktop/safari/SafariExtensionViewController.swift b/src/safari/app/desktop/safari/SafariExtensionViewController.swift index f3f435d338..cfe2295798 100644 --- a/src/safari/app/desktop/safari/SafariExtensionViewController.swift +++ b/src/safari/app/desktop/safari/SafariExtensionViewController.swift @@ -11,6 +11,7 @@ import WebKit class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMessageHandler, WKNavigationDelegate { var webView: WKWebView! + var initedWebView: Bool = false static let shared: SafariExtensionViewController = { let shared = SafariExtensionViewController() @@ -19,6 +20,10 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe }() func initWebView() { + if initedWebView { + return + } + initedWebView = true let parentHeight = SafariExtensionViewController.shared.preferredContentSize.height let parentWidth = SafariExtensionViewController.shared.preferredContentSize.width let webViewConfig = WKWebViewConfiguration()