Last active
August 26, 2020 15:29
-
-
Save revblaze/83d6782ca7b0a2e33d6f2e191a14cb2b to your computer and use it in GitHub Desktop.
WebKit Observer: Page Title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webViewTitleObserver: NSKeyValueObservation? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
webViewTitleObserver = webView.observe(\.title, options: .new) { [weak self] webView, change in | |
if let title = change.newValue as? String { | |
self?.titleDidChange(pageTitle: title) | |
} | |
} | |
} | |
func titleDidChange(pageTitle: String) { | |
let title = pageTitle | |
if title.contains("about:blank") { | |
// Detect _blank targets and new windows | |
} else { | |
self.title = title | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment