From 8dbdfe96b1eae7073f4b92a858e231a3ddf1f630 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 19 Aug 2019 21:04:03 -0400 Subject: [PATCH] init vc and web view on app init --- src/safari/app/desktop/safari/SafariExtensionHandler.swift | 5 +++++ .../app/desktop/safari/SafariExtensionViewController.swift | 5 +++++ 2 files changed, 10 insertions(+) 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()