Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

474 B
Raw Blame
/**
 * Firefox's Node.contains() throws TypeError when the argument is not a
 * Node from this document — native anonymous content around inputs,
 * textareas, and media, or a cross-document range. Chrome returns false.
 */
export function containsNode(
  container: Node | null | undefined,
  node: unknown,
): boolean {
  if (!container || !(node instanceof Node)) {
    return false;
  }
  try {
    return container.contains(node);
  } catch {
    return false;
  }
}