cubiq / add-to-homescreen

Add to home screen call-out for mobile devices
http://cubiq.org/add-to-home-screen
2.29k stars 747 forks source link

Uncaught TypeError: Cannot read property 'appendChild' of null (addtohomescreen.js:553) #282

Open iansv opened 5 years ago

iansv commented 5 years ago

There is an error on this line: // attach all elements to the DOM this.viewport.appendChild(this.element); this.container.appendChild(this.viewport); Does anybody know how to fix it?

RonaldPK commented 5 years ago

I ran into that too. this.container is supposed to refer to document.body, but when it is being defined (on line 279) the document hasn't finished loading yet so document.body is still null.

I "fixed" it by adding

if (this.container == null) this.container = document.body;

to line 451 (where DOM and document are ready). Ugly, but it works.