Closed jhrr closed 7 years ago
Right, so document.body
is indeed null when I call addToHomeScreen
in the head ("as soon as possible" as the docs suggest) and this is causing the null error when it comes time to append the popup to the container node. So, the body has yet to be defined when we make the early instantiation of addToHomeScreen
. It does seem better to move that assignment to the show
method with the rest of the DOM manipulation and it will then be behind the !_DOMReady
guard on line 445.
I was having problems with getting the popup to show up at all and hacking around in the console, (by deleting local storage, setting
shown
to be false, reinstantiating the object etc.) it was clear thatthis.container
in theath.Class
function for some reason was not settingthis.container
correctly, and so, when it came to appending the viewport node to the container I was getting anull
error.Looking around it seemed to make more sense to assign
this.container
in the same part of the code as the other DOM appending actions and doing this did in fact fix my problem; the popup now shows up for me as expected and behaves correctly.I'm not sure quite why this was happening in the first place, but it seems to me that if it doesn't have any other impact elsewhere (I can't see that it does) it makes sense to just define the container along with the
element
andviewport
nodes, like so...