This is to make it work across frames: element.ownerDocument.defaultView is not always === window in the current context, as Rachel found when she was trying to get this to work inside of a puppeteer frame.