You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

集成Google reCAPTCHA时遭遇CORS跨域访问错误求助

Fixing reCAPTCHA CORS Error on Localhost

Hey there, let's get this reCAPTCHA CORS issue sorted out for you. That error usually pops up when something's interfering with the proper response headers from Google's reCAPTCHA script—because normally, Google explicitly allows cross-origin requests for this resource. Here's what you can try:

  • Remove the crossorigin attribute from your script tag
    The reCAPTCHA api.js doesn't require this attribute, and adding it can sometimes trigger unnecessary preflight requests that your local environment might not handle correctly. Use the standard embed code instead:

    <script src="https://www.google.com/recaptcha/api.js"></script>
    
  • Clear your browser cache and hard-refresh the page
    Old cached responses might be missing the required Access-Control-Allow-Origin header. Press Ctrl+Shift+R (or Cmd+Shift+R on Mac) to force a full refresh, or manually clear your browser's cache for localhost.

  • Check for local tools that might intercept requests
    Tools like ad blockers, VPNs, or local proxy software (e.g., Charles, Fiddler) can sometimes modify or strip response headers. Temporarily disable these tools to see if the error goes away.

  • Verify the script URL is correct
    Double-check that you're using the exact URL: https://www.google.com/recaptcha/api.js—no typos, missing s in https, or extra characters.

If none of these work, you can also try loading the script at the end of the <body> tag instead of the <head>—sometimes deferring the load avoids timing-related issues with CORS checks.

内容的提问来源于stack exchange,提问作者Venantius

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:08:24