Skip to content

Commit

Permalink
Merge pull request #28 from Necroskillz/protractor_timeout_fix
Browse files Browse the repository at this point in the history
Render/execute recaptcha outside angular zone to prevent protractor from getting stuck on timeouts
  • Loading branch information
Enngage authored Oct 2, 2018
2 parents 58e4c29 + f9e5dd9 commit 0577418
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class InvisibleReCaptchaComponent extends BaseReCaptchaComponent implemen
*/
execute(): void {
// execute captcha
this.reCaptchaApi.execute(this.captchaId);
this.zone.runOutsideAngular(() => this.reCaptchaApi.execute(this.captchaId));
}

protected captchaSpecificSetup(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Injectable } from '@angular/core';
import { Injectable, NgZone } from '@angular/core';

import { ScriptService } from './script.service';

@Injectable()
export class ReCaptchaV3Service {

constructor(
protected scriptService: ScriptService
protected scriptService: ScriptService,
protected zone: NgZone
) {
}

Expand All @@ -21,10 +22,12 @@ export class ReCaptchaV3Service {
*/
execute(siteKey: string, action: string, callback: (token: string) => void): void {
this.scriptService.registerCaptchaScript(siteKey, (grecaptcha) => {
grecaptcha.execute(siteKey, {
action: action
}).then((token) => {
callback(token);
this.zone.runOutsideAngular(() => {
grecaptcha.execute(siteKey, {
action: action
}).then((token) => {
this.zone.run(() => callback(token));
});
});
});
}
Expand Down

0 comments on commit 0577418

Please sign in to comment.