https://github.com/facido/Demo/raw/master/Demo.zip
As said before, Doc is nil. You just do not wait for the page to load, and immediately rush to use it. I suspect that many other necessary properties are not established. I propose to look for a ready-made working example before doing it yourself. Or refer to the documentation.