RxSwiftCommunity / RxWebKit

RxWebKit is a RxSwift wrapper for WebKit
MIT License
249 stars 104 forks source link

Observing WKWebView url breaks loading content in the web view #18

Closed AttilaTheFun closed 6 years ago

AttilaTheFun commented 6 years ago

I'm instantiating a web view, registering to observe its url, and loading a request in my view controller's view did load. When I comment out the line subscribing to observe it, it loads fine. Any idea what could be going on?

class TestViewController {
    var webView: WKWebView!
    let bag = DisposeBag()
    func viewDidLoad() {
        super.viewDidLoad()
        self.webView = WKWebView(frame: self.view.bounds)
        self.webView.rx.url.subscribe { print($0) }.disposed(by: self.bag)
        self.webView.load(URLRequest(url: URL(string: "https://github.com")!))
    }
}

I set a breakpoint and saw it print the first item, a nil url, but it never called it again.

bobgodwinx commented 6 years ago

@AttilaTheFun change the code to look like this and try again


class TestViewController {
    var webView: WKWebView!
    let bag = DisposeBag()
    func viewDidLoad() {
        super.viewDidLoad()
        self.webView = WKWebView(frame: self.view.bounds)
        self.webView.rx.url.subscribe(onNext: { print($0) }).disposed(by: self.bag)
        self.webView.load(URLRequest(url: URL(string: "https://github.com")!))
    }
}