question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ng-recaptcha tag <recaptcha> causes error “zone.js: Unhandled Promise rejection” when route changes

See original GitHub issue

[Maintainer update 2022-09-26]

Please see this comment.

Summary

I’m submitting a:

  • bug report

Description

I’m using “ng-recaptcha” on Angular component. Im using inside a form like this:

<form class="form-contact"
        [formGroup]="contactForm"
        #formDirective="ngForm" 
        (ngSubmit)="sendMessage(contactForm, formDirective)">
  <re-captcha class="recaptcha"
              formControlName="captcha"
              siteKey="mysitekey">
  </re-captcha>
</form>

Everything seems to be working fine. However, when route changes (ex. user goes to another page) and the AboutComponent is rendered again, an error pops up (multiple times): Unhandled Promise rejection: timeout ; Zone: <root> ; Task: Promise.then ; Value: timeout undefined. I’m 99% sure it’s caused by <re-captcha> tag because error doesn’t show up after removing the tag. Is there a way to render a captcha without errors when route changes (and captcha reloads after im back to component)? Obs: You must wait a few seconds after navigating to another route and back to captcha, then Promise timeout expires and error shows up inside console (google/firefox)

error

https://stackblitz.com/edit/angular-en3spw

Lib versions:

  • ng-recaptcha: 4.0.0-beta.1
  • Angular: 6.1.4
  • Typescript (tsc --version): 2.9.2

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:37
  • Comments:39 (5 by maintainers)

github_iconTop GitHub Comments

43reactions
DethArielcommented, Aug 13, 2022

To not keep you folks in the dark, here’s a small status update.

Why it happens?

This error happens due to the following scenario:

  1. When the component is destroyed, ng-recaptcha invokes the grecaptcha.reset(ID) method
  2. This results in recaptcha invoking the api2/anchor endpoint that @BrentACole mentions
  3. For some reason this endpoint times out
  4. Since this unhandled promise lies inside recaptcha__en.js file there’s no way we could catch it (e.g. patching this file is not an option given such a sophisticated minimization algorithm used)

Why not just skip invoking grecaptcha.reset during ngOnDestroy?

It’s there for a reason, and this reason is #10 .

What can I do?

If you can - ignore it. Add this error to an allowlist in your e2e tests or frontend monitoring software.

Otherwise, you can override the ngOnDestroy method of RecaptchaComponent manually (or create a component fork). Please be aware, that this is a temporary and pretty bad fix that might put you in a very unfortunate position when upgrading component versions! Nevertheless, here’s approximate code for that:

// somewhere in your "main.ts"
import { RecaptchaComponent } from 'ng-recaptcha';
RecaptchaComponent.prototype.ngOnDestroy = function() {
  if (this.subscription) {
    this.subscription.unsubscribe();
  }
}

What next?

I’ve submitted this issue to the recaptcha support team, and I’ll post an update here when I have it.

Thx for bearing with me on that!

9reactions
LuiisFernandocommented, Nov 14, 2018

Anyone solved this error ? I had the same error on angular 4 with recaptcha.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unhandled Promise rejection" when route changes - Stack ...
ng -recaptcha tag <recaptcha> causes error "zone.js: Unhandled Promise rejection" when route changes · 2. Looks more like a library issue, it's ...
Read more >
Unhandled Promise rejection” when route changes
ng -recaptcha tag causes error “zone.js: Unhandled Promise rejection” when route changes.
Read more >
Ng-recaptcha tag <recaptcha> cau.. - W3coded.com
Ng -recaptcha tag causes error “zone.js: Unhandled Promise rejection” when route changes angular,recaptcha,ng,dethariel,chan...
Read more >
ng-recaptcha tag <recaptcha> causes error "zone.js ... - Horje.com
[Code Example] - html - ng-recaptcha tag causes error "zone.js: Unhandled Promise rejection" when route changes. Try following codes. Codes: 1
Read more >
Top issues for DethAriel/ng-recaptcha GitHub project | bleepcoder.com
ng -recaptcha tag <recaptcha> causes error “zone.js: Unhandled Promise rejection” when route changes. bug. kovaljames picture kovaljames·30 Aug 2018·36 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found