Skip to content

AppCheck Error: reCAPTCHA placeholder element must be empty #3089

Description

@anisabboud

Version info

  • Angular: 13.0.3
  • Firebase: 9.6.0 (released last week)
  • 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. In app.module.ts:

    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

Why this happens?

According to an old Stackoverflow question, 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

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.

Activity

  1. google-oss-bot commented on Dec 10, 2021

    @google-oss-bot

    This issue does not seem to follow the issue template. Make sure you provide all the required information.

  2. Sapython commented on Apr 2, 2022

    @Sapython

    Facing the same issue.

  3. Sapython commented on Apr 2, 2022

    @Sapython

    Solved it by enabling isTokenAutoRefreshEnabled: true, in app-check config.

    provideAppCheck(() =>{
          console.log('app check',firebaseApp);
          return initializeAppCheck(firebaseApp, {
            provider: new ReCaptchaV3Provider(
              'abcdefghgijkmnopqrstuvwxyz-',
            ),
            isTokenAutoRefreshEnabled: true,
          })
        }),
  4. anisabboud commented on May 22, 2022

    @anisabboud
    Author

    Update: Seems like this is related to pre-rendering, which causes the ReCaptcha library to be loaded twice.

  5. armando-navarro commented on Oct 10, 2026

    @armando-navarro
    Collaborator

    I tested this with AngularFire 21.0.0-rc.2, released today, which no longer runs App Check during server rendering or prerendering. In an Angular 21 app that prerenders its routes and sets up App Check with ReCaptchaV3Provider as in this report:

    • With 21.0.0-rc.1, the prerender fails with ReferenceError: document is not defined.
    • With 21.0.0-rc.2, the build succeeds, the prerendered page contains no reCAPTCHA markup, and the browser loads the reCAPTCHA script once, with no reCAPTCHA placeholder element must be empty error.

    If you're still seeing this error, could you try 21.0.0-rc.2 (npm install @angular/fire@next) and let me know whether it's gone? If your app needs App Check during server rendering, see App Check during server rendering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp: app-checkApp Check (src/app-check).type: bugDefect: expected behavior doesn't happen.version: legacy (v7-v16)Targets the older modular API (roughly v7-v16).

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions