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

FedCM迁移Google One Tap遇两问题:无弃用方法仍出警告及本地CORS错误

Google One Tap 迁移 FedCM 常见问题解答

问题1:未使用弃用方法却触发警告

警告内容

[GSI_LOGGER]: Your client application uses one of the Google One Tap prompt UI status methods that may stop functioning when FedCM becomes mandatory. Refer to the migration guide to update your code accordingly and opt-in to FedCM to test your changes. Learn more: ...

代码场景

仅使用官方未标记为弃用的getMomentType(),或使用标记为“部分支持”的isSkippedMoment(),仍触发警告:

google.accounts.id.initialize({
  client_id: 'YOUR_CLIENT_ID',
  callback: handleCredentialResponse,
  use_fedcm_for_prompt: true,
});

google.accounts.id.prompt((notification) => {
  if (notification.getMomentType() === 'skipped') {
    console.log('User skipped');
  }
});

疑问解答

  • 为何未使用弃用方法仍出现警告?
    当前GSI Logger的检测逻辑存在误判,只要向prompt()传递回调函数,就会被判定为使用了旧版状态检测路径,即使内部调用的是未标记弃用的方法。另外getMomentType()的底层实现可能依赖了即将被FedCM淘汰的状态接口,导致触发警告。
  • getMomentType()是否已被弃用?
    官方迁移指南未明确标注,但从警告提示和FedCM的设计方向来看,该方法会在FedCM强制生效后停止工作,属于未公开的弃用方法,建议向官方反馈补充到迁移文档中。
  • 向prompt()传递任意回调是否被视为弃用?
    是的。FedCM推荐使用基于事件监听的方式处理状态(如credential_received、skipped事件),而非prompt()的回调参数,当前只要传递回调就会触发警告。

问题2:localhost环境下FedCM触发CORS错误

问题现象

Chrome 144+版本中,开启use_fedcm_for_prompt: true后,在One Tap弹窗选择账户时触发CORS错误,生产HTTPS域名正常运行。

配置确认

  • http://localhost:5173和http://localhost已添加至Google Cloud Console授权JavaScript源
  • OAuth同意屏幕配置正确

解决方案

FedCM本身支持localhost开发,但需满足以下要求:

  • 优先使用http://localhost(不带端口)或http://127.0.0.1进行开发,Chrome 144+对带端口的localhost存在CORS校验异常;
  • 检查Chrome实验性设置:
    1. 打开chrome://flags/#fedcm,确保设置为Enabled
    2. 打开chrome://flags/#fedcm-localhost-support,确保设置为Enabled
  • 清除浏览器缓存及Google账户登录状态后重试,本地缓存可能导致CORS校验逻辑异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.11 14:52:37