Skip to content

Trigger error callback for Network Failures #113

@benhutchins

Description

@benhutchins

Currently, calling ReCaptchaV3Service.execute won't trigger the errorCallback when there is a network failure.

From a brief test, this is because the script tag that is added can fail to load and that is never handled or listened for.

Looking at this code:

        // prepare script elem
        const scriptElem = document.createElement('script');
        scriptElem.innerHTML = '';
        scriptElem.src = this.getCaptchaScriptUrl(useGlobalDomain, render, language);
        scriptElem.async = true;
        scriptElem.defer = true;

        // add script to header
        document.getElementsByTagName('head')[0].appendChild(scriptElem);

This initially allows this to work:

Essentially this needs to be added:

scriptElem.addEventListener('error', (err) => onLoad(err), true);
// scriptElem.onerror = (err) => onLoad(err);

And then the things that rely on this method needs to be updated to expect an error and pass that error along as necessary.

Overall, mobile users can lose network frequently, and this script failing to load can happen in situations. Right now, there is no way to get this error handled through ngx-recaptcha. So in these situations where you need recaptcha and are waiting for the callback, nothing will ever occur.

I've worked around this dumbly by adding a separate timeout that just assumes it failed after a given amount of time, but it'd be nice if the library triggered the errorCallback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions