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

启用FedCM后,通过Google登录按钮认证时One Tap不自动关闭

FedCM模式下Sign In With Google按钮认证后One Tap弹窗无法自动关闭的问题

我正在将Google Identity Services(GSI)迁移到FedCM,当前场景是页面同时展示One Tap弹窗和Sign In With Google按钮。当开启use_fedcm_for_prompt: true后,通过按钮完成认证时,One Tap弹窗不会自动关闭,必须刷新页面才会消失;而未启用FedCM的旧版本中,这个场景下One Tap会自动关闭。

我的Google Identity初始化代码如下:

google.accounts.id.initialize({
  client_id: 'MOCK_CLIENT_ID',
  auto_select: true,
  cancel_on_tap_outside: false,
  callback: () => {
    // 执行认证逻辑
  },
  prompt_parent_id: 'MOCK_PARENT_ID',
  itp_support: true,
  use_fedcm_for_prompt: true
});

// 显示One Tap弹窗
google.accounts.id.prompt();

// 渲染Google登录按钮
// buttonElement 是承载按钮的HTML元素
google.accounts.id.renderButton(buttonElement, {
  theme: 'outline',
  size: 'large',
  logo_alignment: 'left',
  locale: 'en_US',
  text: 'continue_with',
  width: '400',
});

我试过在按钮的click_listener中调用google.accounts.id.cancel()手动关闭One Tap,但启用FedCM后这个方法无法关闭弹窗:

google.accounts.id.renderButton(buttonElement, {
  theme: 'outline',
  size: 'large',
  logo_alignment: 'left',
  locale: 'en_US',
  text: 'continue_with',
  width: '400',
  click_listener: () => {
    google.accounts.id.cancel()
  },
});

有没有办法确保通过按钮认证时One Tap自动关闭?无论通过One Tap还是按钮完成认证,都不需要手动关闭弹窗。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 23:22:21