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

hCaptcha是否存在可提交验证解决方案的data回调?

hCaptcha回调查找方案

hCaptcha存在类似reCAPTCHA的全局挂载对象,你可以通过以下方式定位并调用对应回调提交验证结果:

  • 全局存储hCaptcha配置和实例的核心对象为window.hcaptcha,所有已渲染的hCaptcha组件ID都存放在window.hcaptcha.renderedWidgets数组中
  • 你可以通过window.hcaptcha.getWidgetConfig(组件ID)获取对应组件的完整配置,其中callback字段就是验证通过后需要触发的回调函数
  • 也可以直接调用hCaptcha内置的setResponse方法传入token,自动触发绑定的回调,无需手动查找回调函数

两种实现的代码示例如下:

// 方式1:手动查找回调并调用
const allWidgets = window.hcaptcha.renderedWidgets;
allWidgets.forEach(widgetId => {
  const widgetConfig = window.hcaptcha.getWidgetConfig(widgetId);
  if (typeof widgetConfig.callback === 'function') {
    // 传入从anti-captcha拿到的response token即可完成提交
    widgetConfig.callback('你的验证token');
  }
});

// 方式2:调用内置方法自动触发回调,适配性更强
const targetWidgetId = window.hcaptcha.renderedWidgets[0]; // 单验证场景取第一个组件即可
window.hcaptcha.setResponse(targetWidgetId, '你的验证token');

如果页面存在多个hCaptcha组件,遍历renderedWidgets数组匹配对应页面元素的widget ID即可完成对应验证提交。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 16:48:03