question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'style' of null

See original GitHub issue

react-google-recaptcha version: 1.0.5 react-async-script version: N/A

This error only seems to happen when recaptcha suspects that I’m a robot and shows me the annoying pictures of cars/buses/etc.

This is the error:

Uncaught TypeError: Cannot read property 'style' of null
    at B (VM952 recaptcha__en.js:181)
    at iC.<anonymous> (VM952 recaptcha__en.js:482)
B @ recaptcha__en.js:181
(anonymous) @ recaptcha__en.js:482
setTimeout (async)
a @ recaptcha__en.js:106
f0 @ recaptcha__en.js:482
BG @ recaptcha__en.js:484
t.NP @ recaptcha__en.js:506
r.W @ recaptcha__en.js:325
(anonymous) @ recaptcha__en.js:325
jN @ recaptcha__en.js:12
next @ recaptcha__en.js:12
G @ recaptcha__en.js:14
Promise.then (async)
w @ recaptcha__en.js:14
(anonymous) @ recaptcha__en.js:14
cs @ recaptcha__en.js:14
$v @ recaptcha__en.js:13
Qa @ recaptcha__en.js:325
(anonymous) @ recaptcha__en.js:322
VA @ recaptcha__en.js:90
A2 @ recaptcha__en.js:92
J2.G @ recaptcha__en.js:89

My code:

            <ReCAPTCHA
              ref={e => (this.recaptchaInstance = e)}
              sitekey="my-key"
              size="invisible"
              onChange={this.verifyCaptchaCallback}
              onExpired={() => this.recaptchaInstance.reset()}
              onErrored={err => console.error(`Recaptcha error: ${err}`)}
            />

executeCaptcha = () => {
    this.recaptchaInstance.execute()
}

verifyCaptchaCallback = async response => {
  ...
}

The error doesn’t seem to have any negative effect, so it seems to match what’s written here (https://github.com/google/google-api-javascript-client/issues/281), i.e, that it can be ignored. But that same issue seems to mention a fix: https://github.com/google/google-api-javascript-client/issues/281#issuecomment-339077537

So maybe this library can use this fix?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:30
  • Comments:9

github_iconTop GitHub Comments

6reactions
joepaynescommented, May 26, 2020

Is there any update on this issue? I’m continuing to get this error when Recaptcha suspects that I’m a robot and shows me the annoying pictures of cars/buses/etc.

<ReCAPTCHA
        ref={recaptcha}
        onErrored={() => authError({ code: "recaptcha" })}
        onChange={(value) => {
          let data = { token: value };
          entranceLoading(true);
          verifyRecaptcha(data).then((res) => {
            recaptcha.current.reset();
            if (res.data.success) {
              submitFunc.submit();
            } else {
              authError({ code: "recaptcha" });
            }
          });
        }}
        size="invisible"
        sitekey={...}
      />
4reactions
MrgSubcommented, Jun 11, 2021

The only thing that worked for me is setting a timeout before resetting the recaptcha

setTimeout(() => recaptchaRef.current.reset(), 500);

Not the best approach, and not 100% crash-free but it doesn’t crash every time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript TypeError: Cannot read property 'style' of null
The possible reason behind the error is that the JavaScript runs much earlier than the objects it requires from the webpage are loaded....
Read more >
How To Fix Cannot Read Property 'style' of Null in JavaScript
This error boils down to one problem. The element you are trying to access does not exist in the DOM (document object model)...
Read more >
JavaScript TypeError Cannot Read Property 'style' of Null
JavaScript TypeError Cannot Read Property 'style' of Null ... A typeerror is thrown when a value is not of the expected type. Unlike...
Read more >
Cannot read property 'style' of Null in JavaScript | bobbyhadz
To resolve the "Cannot read property 'style' of null" error, make sure that the DOM element you're accessing the style property on exists....
Read more >
how to fix this error Cannot read property of null (reading 'style')
how to fix this error Cannot read property of null (reading 'style') ... Hi Andrew,. he's just saying that boxElement is null. That...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found