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

ReCaptcha error: Failed to load script #104

Open
birdy90 opened this issue Dec 13, 2021 · 6 comments
Open

ReCaptcha error: Failed to load script #104

birdy90 opened this issue Dec 13, 2021 · 6 comments

Comments

@birdy90
Copy link

birdy90 commented Dec 13, 2021

Hello! Using recaptcha module on my project, and everything seems to work fine. But my sentry shows me ReCaptcha error: Failed to load script error from time to time. That means some users having the issue, though I can't reproduce it. Maybe there's a way I can see the reason script loading has failed? Browsing the plugin.js code didn't give me the answer

This is my config

['@nuxtjs/recaptcha',
  {
    hideBadge: true,
    language: 'ru',
    siteKey: '<my_site_key>',
    version: 2,
    size: 'invisible'
  }
],

And this is how I use it:

<recaptcha
  @error="token = ''"
  @success="token = $event"
  @expired="token = ''"
/>

...

onSubmit() {
  try {
    this.token = await this.$recaptcha.getResponse();
    await this.$recaptcha.reset();
  } catch (e) {
    return false;
  }
  ...
},
@piruo7
Copy link

piruo7 commented Jan 7, 2022

Add the following in nuxt.config.js

head: { ... script: [ { src: 'https://www.google.com/recaptcha/api.js', async: true, defer: true } ] }

@birdy90
Copy link
Author

birdy90 commented Jan 31, 2022

Hm.. I tried your code. After that my auth stopped working. Just nothing happens after clicking 'Login' button. Seems like magic, cause I didn't change anything else except this script in nuxt.config.js.

But, it seems to be more magic here, because it strart working if I set src attribute for script as https://www.recaptcha.net/recaptcha/api.js (found this link in the last version of plugin, v1.0.4)

Unfortunately, I didn't test it for my primary problem. And.. why these links can behave so different though they return almost the same code? And why was it changed in plugin anyway?

@mvrlin
Copy link
Member

mvrlin commented May 19, 2022

@birdy90 Maybe I can add a customSrc option, what do you think?

@birdy90
Copy link
Author

birdy90 commented May 22, 2022

I'm not sure it's a good idea. I suppose recaptcha is not working with multiple links, so it seems to be strange: what else link can I put there if it is not an official one? but you are free to do as you want, of couse :) maybe it would be better to have retry method, and throw error only if several retries failed

@mvrlin
Copy link
Member

mvrlin commented May 23, 2022

I'm not sure it's a good idea. I suppose recaptcha is not working with multiple links, so it seems to be strange: what else link can I put there if it is not an official one? but you are free to do as you want, of couse :) maybe it would be better to have retry method, and throw error only if several retries failed

There was a PR a while ago for using recaptcha.net instead of the google one because of the region problems 🤷‍♂️

@mikeCrafted
Copy link

I am also having problems loading the script. On localhost it works very well, including my remote backend api. But as soon as I push this to production, I get an error instantiating the captcha:
The resource from “https://www.recaptcha.net/recaptcha/enterprise.js?render=<my-key>&render=<my-key>” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
Here is my nuxt.config.js

recaptcha: {
        siteKey: process.env.RECAPTCHA_SITE_KEY,
        hideBadge: true,
        mode: 'enterprise',
        version: 3
    },

What could be the reason that if fails on production server? Apparently the header X-Content-Type-Options: nosniff is set and google returns a wrong content type? Did anyone else experience this issue? I have cloudflare protecting my domain, can I turn off the headers for this specific request, as I assume we can trust Google?

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

No branches or pull requests

4 participants