Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configureWebView is called multiple times for no apparent reason (always after reload of a content of the webview) #40

Closed
vol24pl opened this issue May 9, 2018 · 6 comments

Comments

@vol24pl
Copy link

vol24pl commented May 9, 2018

ViewController#1 with captcha

        reCaptcha.rx.validate(on: view).subscribe(onNext: { [weak self] (token: String) in
            guard let `self` = self else { return }
            self.viewModel.captchaToken = token
            self.dismiss(animated: true)
        }) >>> bag

        reCaptcha.configureWebView { [weak self] webView in
            guard let `self` = self else { return }
            if self.viewModel.captchaToken == nil {
                self.viewModel.openReCaptcha(source: self, webView: webView) //open new VC#2 modally
            }
        }

ViewController#2 with webView

    override func viewDidLoad() {
        super.viewDidLoad()
        setupWebView()
    }

    private func setupWebView() {
        webContainerView.addSubview(webView)
        webView.frame = webContainerView.bounds
        webView.scrollView.isScrollEnabled = false
    }

STR:

  1. Open VC#1
  2. Wait for configureWebView to trigger. It will open VC#2
  3. Don't fill ReCaptcha challange, just dismiss() this VC#2
  4. Wait for about 10 minutes with VC#1 on the screen (I tested it twice with stopwatch at it was 10 mintues +/- 10 seconds both times!)

Expected: Nothing happened
Result: After 10 idle minutes configureWebView closure is oppened again from case .showReCaptcha. It will open VC#2, but there will be now webView this time.

Additional problem:
This line is a workaround:

if self.viewModel.captchaToken == nil { 
    //code 
}

as configureWebView is triggered also right after validation closure is done...

also this code

// Ensures `configureWebView` won't get called multiple times in a short period
            DispatchQueue.main.debounce(interval: 1)

will work only if not debugging. When paused in debug, more than 1 second will pass and there will be more than one consecutive call (just not within one second).

@vol24pl
Copy link
Author

vol24pl commented May 9, 2018

• After waiting 10 minutes and getting this issue, I've waited 15 minutes more to see if there was a 3rd time. There wasn't :)

• In example app from this repo, click validate and wait for 10 minutes. Captcha will dissapear (but it won't trigger configureWebView again). I think this is somehow connected to the captcha expiration.

@vol24pl
Copy link
Author

vol24pl commented May 10, 2018

configureWebView is also called each time I fail to verify captcha. Captcha is reloaded than with "Please try again" message. Why's that? The view is already configured.

TO SUM EVERYTHING UP

As far as my understanding goes, configureWebView is called each time a content of the webView is reloaded (due to a timeout or failing captcha challange). It should be unnecessary, as webView needs to be set up only once. Calling this method many times introduces unexpected behaviours.

@vol24pl vol24pl changed the title configureWebView is called multiple times for no apparent reason configureWebView is called multiple times for no apparent reason (after reload of a content of the webview) May 10, 2018
@vol24pl vol24pl changed the title configureWebView is called multiple times for no apparent reason (after reload of a content of the webview) configureWebView is called multiple times for no apparent reason (always after reload of a content of the webview) May 10, 2018
@fjcaetano
Copy link
Owner

It seems the problem might be in the way the JS code is checking if the captcha needs to be displayed. It's simply watching for any mutations in a div (recaptcha.html) and that might be too broad.

As I understand, you're being able to use the lib with your workaround, right? I currently don't have much time to look into this, so if you're able to find anything on this or work on a fix, feel free to open a PR, I'll appreciate it.

@fjcaetano
Copy link
Owner

@vol24pl I was able reproduce the issue and stop it from happening on PR #42. However, when the second configure trigger was supposed to happen, the webview is becoming blank and it stops working. I haven't been able to fix that and, to be honest, I don't know if there is a fix.

I'd love if you could take a look at #42 to check what do you think about it and if it works for you like that.

@vol24pl
Copy link
Author

vol24pl commented Jul 18, 2018

Sorry for delayed responses, but my project that used your library is not maintained by me anymore.

I think that webview becoming blank is a proper behavior for captcha that is timed out.

Anyway I’ll try to find time and look into it :)

@fjcaetano
Copy link
Owner

No problem. I'm also not being able to give as much time to this project as needed. I'll leave the issue open for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants