2

I'm developing a browser extension that share code between chrome and safari, basically it's an html page that I load up in a WKWebView on safari app extension (and an iframe on chrome extension).

Everything works fine apart from links that won't open in the safari app extension popover if they have target="_blank" or are popups like facebook login.

Anyone know if it is possible to have safari open them up as if clicked on in an ordinary safari tab?

I've tried to see if the WKWebView sets a global safari object in my html content, but it seems not, so this Safari Extension Popover Links does not work (results in ReferenceError: Can't find variable: safari).

This is how I load the web view in my SafariExtensionViewController:

override func viewDidLoad() {
    super.viewDidLoad()

    ...

    self.view.addSubview(webView)
    webView.navigationDelegate = self

    ...

    webView.load("\(baseUrl)?url=\(currentUrl)")
  }

and an extension to make the load part work:

extension WKWebView {
  func load(_ urlString: String) {
    if let url = URL(string: urlString) {
      let request = URLRequest(url: url)
      load(request)
    }
  }
}
jnaO
  • 109
  • 1
  • 5

1 Answers1

0

Safari Technology Preview 77 (6March 2019) and likely 12.1.x of regular Safari.

Made the window.safari object available in frames opened to safari-extension:// resources

https://webkit.org/blog/8658/release-notes-for-safari-technology-preview-77/

So if you go by that method you should be OK.

Matt Sephton
  • 3,711
  • 4
  • 35
  • 46