AppCheck Error: reCAPTCHA placeholder element must be empty
- 主要语言
- TypeScript
- 星标
- 7.8k
- 派生
- 2.2k
- 平均合并
- 22 小时 28 分钟
- 30 天内合并 PR
- 6
描述
### Version info
- **Angular:** 13.0.3
- **Firebase:** 9.6.0 (released [last week](https://firebase.google.com/support/release-notes/js))
- **AngularFire:** 7.2.0 (with rxfire 6.0.3)
- **FirebaseUI:** 6.0.0 (with firebaseui-angular 6.1.0)
### How to reproduce these conditions
Added and configured **Firebase App Check** following the [documentation](https://firebase.google.com/docs/app-check/web/recaptcha-provider#initialize). In `app.module.ts`:
```typescript
provideAppCheck(() => initializeAppCheck(getApp(),
{ provider: new ReCaptchaV3Provider(recaptcha3SiteKey), isTokenAutoRefreshEnabled: true })),
```
**Error in production build:** (`ng build --configuration=production` deployed on Firebase Hosting)
`Error: reCAPTCHA placeholder element must be empty` which then causes: `@firebase/firestore: Could not reach Cloud Firestore backend.`

**Why this happens?**
According to an old [Stackoverflow question](https://stackoverflow.com/questions/37021241/error-recaptcha-placeholder-element-must-be-empty), it might be because "You are loading the google recaptcha library twice."
**Network tab**
Indeed, looking at the Network tab, `recaptcha__en.js` is loaded twice.

**Could the second recaptcha be loaded by something else?**
I initially suspected FirebaseUI is loading the second recaptcha.
However, commenting out `provideAppCheck()` in `app.module.ts` then checking the network tab shows 0 instances of `recaptcha__en.js`, leading to the conclusion that both were loaded through `provideAppCheck()`.
### Summary
`provideAppCheck()` seems to load recaptcha library twice, causing a console error and disrupting Firestore completely.
贡献指南
调研方向
Start at the provideAppCheck() configuration in app.module.ts and reproduce with ng build --configuration=production while watching the Network tab. Compare the production initialization path with the case where provideAppCheck() is commented out. Done means reCAPTCHA loads once, the placeholder error is absent, and Firestore reaches its backend.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- angular, firebase, typescript
- 领域
- cloud, security
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100