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

如何修复切换reCaptcha版本后出现的无效密钥及api.js加载错误

Fixing reCAPTCHA v2 Error & Slow Site Load After Failed v3 Switch

Let’s work through this issue step by step—this is almost certainly leftover reCAPTCHA v3 code conflicting with your restored v2 setup, causing that invalid site key error and dragging down your site’s performance.

Step 1: Hunt Down and Remove All v3-Specific Code

The error mentions grecaptcha.execute(), which is a v3-only method (v2 doesn’t use execute for its checkbox or invisible widgets). Here’s what to check:

  • Look for any code blocks calling grecaptcha.execute() (like the executeOnHomepage function referenced in your error). Delete or comment out these sections entirely—they don’t belong in a v2 setup.
  • Verify your reCAPTCHA script tag:
    • Remove any v3-style script tags like this:
      <script src="https://www.google.com/recaptcha/api.js?render=YOUR_V3_KEY"></script>
      
    • Replace it with the standard v2 script (for checkbox widgets):
      <script src="https://www.google.com/recaptcha/api.js"></script>
      
      Or for invisible v2 widgets, use the explicit load version:
      <script src="https://www.google.com/recaptcha/api.js?onload=yourCallbackFunction&render=explicit"></script>
      

Step 2: Confirm Your Site Key is for reCAPTCHA v2

That "Invalid site key" error often happens if you’re accidentally using a v3 key with v2:

  • Go to your Google Developers Console and double-check that the site key in your code is assigned to a reCAPTCHA v2 (Checkbox or Invisible) project, not v3.
  • Verify your v2 widget code has the correct key:
    <div class="g-recaptcha" data-sitekey="YOUR_VALID_V2_KEY"></div>
    

Step 3: Clear All Caches to Eliminate Residual Resources

Old cached scripts can keep v3 code lingering even after you delete it:

  • Browser cache: Force a hard refresh (Ctrl+Shift+R on Windows, Cmd+Shift+R on Mac) to bypass cached files.
  • Server/CDN cache: If you use a CDN or server-side caching (e.g., WordPress plugins), clear those caches to ensure your updated code is served to visitors.
  • Framework/theme files: If you’re using a CMS or framework (WordPress, React, etc.), check global script files (like functions.php in WordPress, or App.js in React) for any hidden v3 initialization code that might have been added earlier.

Step 4: Test for Errors and Performance Improvements

After making these changes:

  • Open your browser’s DevTools (F12), go to the Console tab, and refresh the page. The Invalid site key error should be gone.
  • Check the Network tab to confirm only the v2 reCAPTCHA script is loading—no v3 scripts with the render parameter should be present.
  • Monitor your site’s load time; removing the conflicting v3 code should resolve the slowdown caused by the failed script execution.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 07:40:19