Unfortunately those methods do not work with Retool
They require access to the window and the DOM to understand when those events occur. However, Retool code/JS is executed in a sandbox for security purposes and this is why users are not able to use window or document.
This had been a feature request from another user who wanted the same functionality but this was closed because it seems that the sandbox executor is not able to allow javascript in Retool to interact with the browser.