Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on user exit without complete throw error #192

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/recaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,35 @@ export default class ReCAPTCHA extends React.Component {
}

executeAsync() {
return new Promise((resolve, reject) => {
const original = new Promise((resolve, reject) => {
this.executionResolve = resolve;
this.executionReject = reject;
this.execute();
});
if (!("MutationObserver" in window)) return original;
return new Promise((resolve, reject) => {
const frame = document
.querySelector('iframe[src*="google.com/recaptcha/api2/bframe"]')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 🤔 we should be cautious using a querySelector reaching for a very specific recaptcha related src that could change at will by google.

?.parentNode
?.parentNode;
if (!frame) {
return original.then(resolve).catch(reject);
}
const observer = new MutationObserver(() => {
if (Number(frame.style.opacity) === 0) {
reject(new Error('User clicked outside'));
observer.disconnect();
}
});
observer.observe(frame, { attributes: true, attributeFilter: ["style"] });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📓 it also appears that if frame is null, from an unfound querySelector, the .observe methods errors.

return original.then(result => {
observer.disconnect();
resolve(result);
}).catch(e => {
observer.disconnect();
reject(e);
});
});
}

reset() {
Expand Down