If you use this and it works then it's probably worth checking your site's Content-Security-Policy. Either you don't have one or you have it set to allow 'unsafe-inline' to allow inline scripts, and that is potentially quite a serious security problem.