Check that document isn't undefined.