Currently the code present in the readme will cause an exception if executed before the document has been parsed, this PR fixes that by preventing that from happening.
How to reproduce the error
Place the readme's code in a script tag inside the <head> element of an html page. More concretely, what I'm doing is building the readme's code along with the penpal library into a single js file using webpack and then importing that script into a page in the following way:
It makes the code check if the document has already been parsed and, in case that it hasn't, it sets up an event that will be triggered when the document is ready.
Currently the code present in the readme will cause an exception if executed before the document has been parsed, this PR fixes that by preventing that from happening.
How to reproduce the error
Place the readme's code in a script tag inside the
<head>
element of an html page. More concretely, what I'm doing is building the readme's code along with the penpal library into a single js file using webpack and then importing that script into a page in the following way:How this PR fixes the problem
It makes the code check if the document has already been parsed and, in case that it hasn't, it sets up an event that will be triggered when the document is ready.