Fix issue with invalid document when script tag is whitelisted