Fix an issue where the script would crash for document without a <head>.