Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

TypeError: Cannot read property 'body' of undefined

1669175814
Jiboux
Pro
Sheet Author
Compendium Curator
Hello All, Since 2 years I have been woding on API and Character Sheet for Earthdan 4th Ed, I have had all sorts of bugs I have been able to track (often with the help of the community) or accept to live with (often with the mental support of the community), but there is still one coming back and back again where the API crashes with a message as below TypeError: Cannot read property 'body' of undefined I have tried to understand what type of events lead to this, and it seems very random, even sometimes being there waiting for me after I left the game running for some time... I have seen this message in various other threads but never found someone that actually pointed out a cause to it... <a href="https://app.roll20.net/forum/post/6467921/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/6467921/slug%7D</a> <a href="https://app.roll20.net/forum/post/8404492/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/8404492/slug%7D</a> <a href="https://app.roll20.net/forum/post/10285501/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/10285501/slug%7D</a> Only thing I am pretty sure is that it looks to be in the roll20 side (even if it may be a wrong value sent by my code), as I have nowhere in my code any object where I try to read a "body" property... Did anyone track this one down and has more clue on what can cause it ?
1669207967
timmaugh
Pro
API Scripter
Can you post a gist of your sheet code and another for your mod script?
1669245490
Jiboux
Pro
Sheet Author
Compendium Curator
Hello Timmaugh, Latest HTML (not released yet) Earthdawn (FASA Official) Latest published API 02.042 The 2 versions do not "match" (I am working on a new version of both, and have the latest in progress HTML in Github, but the API is the last release), but they should still work together, and the problem has been there forever, so any version should have the problem...
1669328591
Oosh
Sheet Author
API Scripter
It sounds like something in there is trying to call a function that points to document.body, which isn't accessible from the sandbox. Do you still get the error with the API script disabled (just to make sure it is actually the cause)? There's a lot of code there to go through....
1669353055
Jiboux
Pro
Sheet Author
Compendium Curator
Thanks oosh Yup, there is a lot of code... We have been working our asses in the 2 last years :D gotta love this game (If you don't know it, try it !° What is document.body ? That could be interesting to narrow it down The API in question is the companion API that runs with our character sheet... If it is disabled, there is not really a game to play, so it is difficult to actually disable it and see if the fault comes...
1669422220

Edited 1669422717
Oosh
Sheet Author
API Scripter
Document is the top node of the DOM in web development - it's not accessible from the Roll20 sandbox, unlike in a normal web development environment. If you're using any functions or modules from somewhere else they might be assuming the document object exists and attempting to access something of document.body - that would generally be for attempting to insert some HTML elements, as injecting scripts or styles would generally go on the head and not the body. If you've got any external code or libraries that deal with HTML, that might be a place to look? Edit - Actually, looking at those other threads, it looks like it might be generated internally, no idea what might be causing it though. If there's any way of having the API script active with a different character sheet, I'd try that to narrow it down to the character sheet or the API script. The character sheet seems more likely to be looking for document.body - it has its own iframe document object.
1669475003
Jiboux
Pro
Sheet Author
Compendium Curator
Oh, this is very interesting idea... With this being told, I may have a few suspects in the API (the sheet is pure HTML and CSS, and we don't even use jqueries, so I don't really see any dangerous interactions with the HTML... On the other end, the API uses several HTML functions to generate messages sent to the chat for roll result and Human Manchine Interface... This could be a lead, even if what I fail to understand is in this hypothesis why (and something similar was mentioned in one of the links, and also happens to me), the crash seems to happen randomly without a clear user action, and even happens on sessions that were left idle ...