Skip to content

Commit

Permalink
fix: catch on load handler error
Browse files Browse the repository at this point in the history
  • Loading branch information
faris-imi committed Oct 25, 2023
1 parent 938043c commit e796696
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,25 @@ class HCaptcha extends React.Component {
});
}

handleOnLoad () {
handleOnLoad () {
this.setState({ isApiReady: true }, () => {
const element = getMountElement(this.props.scriptLocation);
const frame = getFrame(element);
try {
const element = getMountElement(this.props.scriptLocation);
const frame = getFrame(element);

this._hcaptcha = frame.window.hcaptcha;
this._hcaptcha = frame.window.hcaptcha;

// render captcha and wait for captcha id
this.renderCaptcha(() => {

// render captcha and wait for captcha id
this.renderCaptcha(() => {
// trigger onLoad if it exists

const { onLoad } = this.props;
if (onLoad) onLoad();
});
});
} catch (e) {
this.sentryHub?.captureException(e);
}
});
}

Expand Down

0 comments on commit e796696

Please sign in to comment.