i have recently been facing issues with a polyfill library (Prototype.js) and recaptcha. for some reason its acting dicey and throwing a "Unexpected token x in JSON at position 0" error and the wheel spins and stops after a while, without loading the challenge. When i updated the prototype.js to its latest version (1.7.3) it worked fine. not sure what is happening here. doesn't look like changes have been made to any of the files (recaptcha or prototype) and the behaviour is inconsistent in different micro sites. Would appreciate any help please. Sorry I cannot share the code since it is for a client.
Asked
Active
Viewed 350 times
1 Answers
0
EDIT
A solution was posted on https://stackoverflow.com/a/64808781/5067818 . This worked well for me and I've found it better than using an iframe!
I'm facing the same issue in my company. After reading a few other related stackoverflow issues and debugging, we've confirmed what people reported: recaptcha javascript code (loaded with a script tag) was interacting with another javascript within our project. In our case, it was ajax4jsf/framework.pack.js, but there are reports here of the same thing occurring with prototype.js.
From what I've read so far, a quick fix was achieved by embedding recaptcha into an iframe. I'm trying to solve it by making sure recaptcha scripts run independently, though (without success so far hahah).
Cheers!

Lincoln Alves
- 546
- 5
- 13
-
Thanks Lincoln, notes in the articles you shared helped. I am still trying to debug the code to get a long term fix and to identify a way to stop this from happening again. Will keep the thread informed and updated. – Sachin K Nov 13 '20 at 11:10
-
Glad to help! I think our problem is the same in the end...ajax4jsf script has prototype.js inside. The thing is, prototype.js overrides a few native javascript functionalities. In my case, prototype.js was overriding Array.prototype.reduce. – Lincoln Alves Nov 13 '20 at 11:19
-
I had the same issue. Ended up overriding the Array.prototype.reduce and it worked fine. Any clue why this happened suddenly? – Sachin K Nov 16 '20 at 04:12
-
As so far I couldn't find an unminified version of Recaptcha js API, I can't say for sure...my guess is the latest version started using Array.prototype.reduce in one or more places, generating a chain reaction that resulted in this bug...anyway, I'm glad it's over! – Lincoln Alves Nov 16 '20 at 16:12
-
You bet, i'm glad it's over. I checked with the google team and they mentioned that no changes were done to the v2 code, and I didn't either. Strange! – Sachin K Nov 18 '20 at 06:01