Skip to content

a.target.closest #18

Description

@harryfear

Getting error a.target.closest is not a function on some Chrome contexts:—

  // Add URL to queue on mouse hover, after timeout
  const mouseOverListener = (event) => {
    const elm = event.target.closest("a");
    if (elm && elm.href && !alreadyPrefetched.has(elm.href)) {
      hoverTimer = setTimeout(() => {
        addUrlToQueue(elm.href, true);
      }, window.FPConfig.hoverDelay);
    }
  };

  // Prefetch on touchstart on mobile
  const touchStartListener = (event) => {
    const elm = event.target.closest("a");
    if (elm && elm.href && !alreadyPrefetched.has(elm.href))
      addUrlToQueue(elm.href, true);
  };

  // Clear timeout on mouse out if not already prefetched
  const mouseOutListener = (event) => {
    const elm = event.target.closest("a");
    if (elm && elm.href && !alreadyPrefetched.has(elm.href)) {
      clearTimeout(hoverTimer);
    }
  };

Claude says: "This can happen if the event target is a text node or a non-element node."

Element.closest() method is supported in Chrome 75 but I'm seeing the error in Chrome 75-128.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions