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

Javascript exception occurred #69

Closed
elodd opened this issue Mar 20, 2019 · 10 comments
Closed

Javascript exception occurred #69

elodd opened this issue Mar 20, 2019 · 10 comments

Comments

@elodd
Copy link

elodd commented Mar 20, 2019

ReCaptchaDomain is http://localhost/, but at validate the webview is interrupted with a Javascript exception expecting ReCaptchaDomain in the html?

Unexpected Error: Error Domain=WKErrorDomain Code=4 \"A JavaScript exception occurred\"
UserInfo={WKJavaScriptExceptionLineNumber=24, WKJavaScriptExceptionMessage=TypeError:
Argument 1 (\'target\') to MutationObserver.observe must be an instance of Node,
WKJavaScriptExceptionColumnNumber=13, WKJavaScriptExceptionSourceURL=http://localhost/,
NSLocalizedDescription=A JavaScript exception occurred}"
@fjcaetano
Copy link
Owner

fjcaetano commented Mar 20, 2019

Hi @elodd, I just merged PR #68, which adds some documentation to README explaining that when generating your ReCaptcha key you must uncheck Verify the origin of reCAPTCHA solutions when using localhost as the domain.

image

Could you give that a go and let me know if it works?

@fjcaetano
Copy link
Owner

Hey @elodd, were you able to solve this? Is there anything we can do to improve the library?

@elodd elodd reopened this Mar 28, 2019
@elodd
Copy link
Author

elodd commented Mar 28, 2019

Hi @fjcaetano,

No, unfortunately not, but minimised failure occasions by doing a redundant call for the setupReCaptcha functions when the above error occurs and maximised recapture security but always showing visual challenge.

When:

  1. ReCaptchaKey is confirmed the same when registering and in the app.
  2. ReCaptchaDomain is registered as localhost and http://localhost in the app.
  3. Verify the origin of reCAPTCHA solutions is unchecked.

The above Javascript exception still occurs and breaks the flow.

@fjcaetano
Copy link
Owner

I'll investigate this further. I've just closed issue #70, which was a duplicate of this one.

The error there seemed to be because validate was being called too quickly, so it might be an issue with the logic that checks if all the JS resources were loaded.

A workaround was to add some delay before validating. Could you check if that minimizes the issue for you? Also, is this issue only happening in development (since you're using localhost) or in production also?

@elodd
Copy link
Author

elodd commented Mar 29, 2019

My understanding that since the token key is created on the mobile phone and not on a website or dns I need localhost for security reasons.

@fjcaetano
Copy link
Owner

@elodd you're free to use any domains you want, that's why the property is configurable. Did you try adding the delay I mentioned?

Using this library is a three-step process:

  1. Load the library (by initializing it)
  2. Configure the view (this may or may not be executed, depends on the JS code)
  3. Validate the challenge

Ideally, you shouldn't try and execute all three at once. If that's what you're doing, you shouldn't run into any problems, but it's safer to add some time between them, specially loading and validating. Either way, any problems you may be encountering should be investigated.

@fjcaetano
Copy link
Owner

Are you by any chance using ReCaptcha v3? It looks like v3 is causing many issues with the library. If possible, please, try and use a v2 Invisible ReCaptcha key.

I'll look into adding support for v3 keys.

@elodd
Copy link
Author

elodd commented Apr 7, 2019

I used a v2 Invisible ReCaptcha key and a delay did not help.

@elodd elodd reopened this Apr 8, 2019
@fjcaetano
Copy link
Owner

@elodd I was able to reproduce that issue by registering a wrong key or domain. Could you double check that on your side? Also, please check if you're using Google ReCaptcha's SITE KEY for the client side integration.

@elodd
Copy link
Author

elodd commented Apr 10, 2019

@fjcaetano Sorry I moved on working with a different project.

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