Manually clear orphaned recaptcha challenge overlay in android webviews (#53)

* try manually clear any left over recaptcha overalys

* add alert to debug webview

* disable settings check for netlify build

* Update fix for removing challenge, as g-recaptcha-bubble-arrow is now always shown

* Remove alert for debugging webview

* Put back requirement for config setting and make sure it redirects to welcome if not present.

* Add comment to explain bodge.

* Remove unrelated code
pull/28192/head
David Langley 2024-09-18 17:56:18 +01:00 committed by GitHub
parent 0bbed853da
commit 154bf33fa1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 0 deletions

View File

@ -63,6 +63,19 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
public componentWillUnmount(): void { public componentWillUnmount(): void {
this.resetRecaptcha(); this.resetRecaptcha();
// Resettting the captcha does not clear the challenge overlay from the body in android webviews.
// Search for an iframe with the challenge src and remove it's topmost ancestor from the body.
// TODO: Remove this when the "mobile_register" page is retired.
const iframes = document.querySelectorAll("iframe");
for (const iframe of iframes) {
if (iframe.src.includes("https://www.recaptcha.net/recaptcha/api2/bframe")) {
let parentBeforeBody: HTMLElement | null = iframe;
do {
parentBeforeBody = parentBeforeBody.parentElement;
} while (parentBeforeBody?.parentElement && parentBeforeBody.parentElement != document.body);
parentBeforeBody?.remove();
}
}
} }
// Borrowed directly from: https://github.com/codeep/react-recaptcha-google/commit/e118fa5670fa268426969323b2e7fe77698376ba // Borrowed directly from: https://github.com/codeep/react-recaptcha-google/commit/e118fa5670fa268426969323b2e7fe77698376ba