Suggestion: use window.onload instead of setTimeout.

To make sure the dom window is finished to load and the document is available, you can use window.onload or listen 'DOMContentLoaded` event.

Using setTimeout, it is possible to get a error saying document is not available if the page is not finished to load in 1 second.