The problem wasn't the script itself, it was the CSP policy of the website I was visiting. The script worked well on another website. I am using firefox, and it seems you can't disable CSP for a particular website or tab in firefox.