CaliStyle / ng-intercom

Angular 7+ Wrapper for Intercom.com
MIT License
54 stars 46 forks source link

If no script tag is on page a parentNode error is thrown #31

Closed nearbycoder closed 6 years ago

nearbycoder commented 6 years ago

First off love the easy to use library that you have. I ran into a bug recently when trying to use this library. We didn't have a script tag on our page and we ended up getting a parentNode error because of this which was a bit misleading.

Would it be a more ideal situation to rely on the head element here or possible add some documentation about the requirement of at least one script tag? Thanks and if you would like me to put a PR in for this change just let me know!

https://github.com/CaliStyle/angular2-intercom/blob/56135794e7a351215b68720ccfae2c84588d136b/src/util/load-intercom.ts#L11

wbhob commented 6 years ago

Well a few lines above it, it creates a script tag in the DOM. This is a direct port of the Intercom instantiation code. Perhaps document.write-ing a script tag to start would fix it in this script?

nearbycoder commented 6 years ago

@wbhob yes I see that however it is not appending it to the DOM until the next line after

x.parentNode.insertBefore(s, x);

The createElement api doesn't insert it into the document body until you do appendChild or like the line above says insertBefore.

wbhob commented 6 years ago

Any news on this? @nearbycoder is it still a problem?

nearbycoder commented 6 years ago

@wbhob we ended up just adding a blank script tag to get it to work. Not a perfect fix but it worked!

wbhob commented 6 years ago

I may modify the script to just appendChild to the document. Rarely will people actually have a script tag in Angular. I'll take a look later today!

wbhob commented 6 years ago

Fixed by 1a8c401e1c09bd1b2a4b8a70c040a3b5f57116fb