我正在测试 FedCM,因为第三方 cookie 正在逐步淘汰。但是我发现迁移后无法正常使用。
迁移指南中的第一步说:
我修改了它们。我当前的代码如下所示:
<div id="g_id_onload"
class="google-login"
:data-client_id="constants.GOOGLE_CLIENT_ID"
:data-use_fedcm_for_prompt="true"
:data-auto_select="true"
:data-itp_support="true"
:data-skip_prompt_cookie="localToken"
:data-callback="handleGoogleOneTapResponse"
:data-prompt_parent_id="g_id_onload"
:data-ux_mode="'popup'">
</div>
function renderGoogleSignInBtn() {
const google = window.google;
if (google) {
google.accounts.id.initialize({
client_id: constants.GOOGLE_CLIENT_ID,
callback: handleGoogleOneTapResponse,
use_fedcm_for_prompt: true,
});
google.accounts.id.prompt();
}
}
在 Mac 上运行正常,但在 Windows 上报告错误!
我不太明白为什么会出现这样的错误。我需要做什么才能成功迁移?
看起来该错误是由于您的代码调用了
google.accounts.id.prompt();
两次(一次来自 HTML,一次来自 JavaScript)。您无需在代码中同时包含 HTML 和 JavaScript 即可使用 One Tap。