angular / angular/angularfire

AppCheck Error: reCAPTCHA placeholder element must be empty

Đang mở
#3,089 4 bình luận 2 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
7.8k
Fork
2.2k
Merge trung bình
22 giờ 28 phút
Pull request đã merge (30 ngày)
6

Mô tả

### 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.`

![reCAPTCHA error in prod](https://user-images.githubusercontent.com/5672108/145540484-d41fd76f-6f83-4012-a4a1-245ba344fc2f.png)

**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.
![reCAPTCHA loaded twice](https://user-images.githubusercontent.com/5672108/145541040-531bf37b-4b76-4ce7-a61a-b5aef7630952.png)

**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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
angular, firebase, typescript
Lĩnh vực
cloud, security
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.