Как известно сервисы Google в Китае не работают, но очень хочется чтобы заработала Google reCAPTCHA. Есть у меня сервис вот такой:
import {Injectable, OnDestroy} from "@angular/core";
import {Observable} from "rxjs/Observable";
import {BehaviorSubject} from "rxjs/BehaviorSubject";
import {Router, NavigationEnd} from "@angular/router";
declare var grecaptcha: any;
@Injectable()
export class ReCaptchaDynamicLanguageLoaderService implements OnDestroy {
ngOnDestroy(): void {
ReCaptchaDynamicLanguageLoaderService.ready.next(null);
}
public ready: Observable<any>;
public language: string;
public langParam: string;
private url = "https://www.recaptcha.net:443/recaptcha/";
private static ready: BehaviorSubject<any> = new BehaviorSubject<any>(null);
constructor(
private router: Router
) {
window["__recaptcha_api"] = this.url;
this.ng2ReCaptchaLoaded();
this.setLanguage();
this.ready = ReCaptchaDynamicLanguageLoaderService.ready.asObservable();
}
public updateLanguage(newLang: string): void {
this.language = newLang;
ReCaptchaDynamicLanguageLoaderService.ready.next(null);
this.init();
}
private ng2ReCaptchaLoaded(): void {
window["ng2recaptchaloaded"] = () => {
ReCaptchaDynamicLanguageLoaderService.ready.next(grecaptcha);
};
}
public setLanguage(lang: string = null): void {
if (lang) {
if (lang !== this.language) {
this.updateLanguage(lang);
}
} else {
this.router.events
.subscribe((event) => {
if (event instanceof NavigationEnd) {
this.language = event.url.substring(1, 3);
this.init();
}
});
}
}
private addScript(langParam: string): void {
let script: HTMLScriptElement = document.createElement("script") as HTMLScriptElement;
script.innerHTML = "";
script.src = `${this.url}api.js?render=explicit&onload=ng2recaptchaloaded${langParam}`;
script.async = true;
script.defer = true;
document.head.appendChild(script);
}
private init(): void {
let langParam: string = this.language
? "&hl=" + this.language
: "";
if (this.langParam !== langParam) {
this.langParam = langParam;
if (ReCaptchaDynamicLanguageLoaderService.ready) {
let isActive: any = ReCaptchaDynamicLanguageLoaderService.ready.getValue();
if (isActive) {
return;
}
}
this.addScript(langParam);
}
}
}
Где я пытаюсь обойти "великий" китайски фаервол через
https://www.recaptcha.net:443/recaptcha/
Получаю ошибку в консоле:
VM791 recaptcha__en.js:218 Uncaught DOMException: Failed to construct 'Worker': Script at 'https://www.google.com/recaptcha/api2/webworker.js?hl=en&v=v1523860362251' cannot be accessed from origin 'https://www.recaptcha.net'.
at new Xm (https://www.gstatic.com/recaptcha/api2/v1523860362251/recaptcha__en.js:218:623)
at new Ao (https://www.gstatic.com/recaptcha/api2/v1523860362251/recaptcha__en.js:247:433)
at Object.init (https://www.gstatic.com/recaptcha/api2/v1523860362251/recaptcha__en.js:248:72)
at https://www.recaptcha.net/recaptcha/api2/anchor?k=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI&co=aHR0cDovL2xvY2FsaG9zdDo1NjU5Nw..&hl=en&v=v1523860362251&size=normal&cb=gtaulfjyul46:197:29
Получаю ошибку в Google reCAPTCHA:
Please upgrade to a supported browser to get a reCAPTCHA challenge.
Alternatively if you think you are getting this page in error, please check your internet connection and reload.
Why is this happening to me?