Skip to content

Commit

Permalink
Handle mouseoverListener’s event.target.closest sometimes not existing
Browse files Browse the repository at this point in the history
  • Loading branch information
dieulot committed Jul 1, 2022
1 parent e59ce5e commit 00249af
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions instantpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ function mouseoverListener(event) {
return
}

if (!('closest' in event.target)) {
// Without this check sometimes an error “event.target.closest is not a function” is thrown, for unknown reasons
// That error denotes that `event.target` isn’t undefined. My best guess is that it’s the Document.

// Details could be gleaned from throwing such an error:
//throw new TypeError(`instant.page non-element event target: timeStamp=${~~event.timeStamp}, type=${event.type}, typeof=${typeof event.target}, nodeType=${event.target.nodeType}, nodeName=${event.target.nodeName}, viewport=${innerWidth}x${innerHeight}, coords=${event.clientX}x${event.clientY}, scroll=${scrollX}x${scrollY}`)

return
}
const linkElement = event.target.closest('a')

if (!isPreloadable(linkElement)) {
Expand Down

0 comments on commit 00249af

Please sign in to comment.