Please attach a test project that replicates this problem. Also, specify what is in the resource? You can attach the project and the file for the resource here or in a forum PM.
@yourfriendkarol
This code contains an event handler. It should be added to the page before it is downloaded (preferably). Use "Browser -> execute every time the page loads". From "Tools -> execute the code" access to the root object "windows" is not. From this error there is - no "windows.document"