rangyinputs icon indicating copy to clipboard operation
rangyinputs copied to clipboard

getBody().appendChild(testTextArea); throws Cannot read property 'appendChild' of undefined

Open ndvbd opened this issue 5 years ago • 4 comments

We use rangyinputs in a Chrome extension, and many times the line getBody().appendChild(testTextArea); throws Cannot read property 'appendChild' of undefined Probably in pages where they don't have a proper "body".

ndvbd avatar Jul 27 '20 17:07 ndvbd

It usually happens if the script is being called before the body is rendered. Try running the chrome extension script once the body is rendered or loaded. Use something like window.onload.

kamlekar avatar Jul 27 '20 17:07 kamlekar

But the problem is that it is out of our control, because the rangyinputs code is hooking the $(document).ready function:

```

$(document).ready(function() { var testTextArea = document.createElement("textarea");

    getBody().appendChild(testTextArea);

ndvbd avatar Jul 27 '20 17:07 ndvbd

hmm strange. It should not be an issue with this library though. Maybe you are loading multiple jquery libraries or maybe the latest one instead of the actual jquery library version this library relies on?

I don't think there will be a page without a body element though. If you feel so, maybe elaborate on this (give an example?)

Try checking console errors

kamlekar avatar Jul 28 '20 03:07 kamlekar

Well, I don't know. I use Sentry, and I get many reports on this error, but I can't reproduce it.

ndvbd avatar Jul 28 '20 18:07 ndvbd