import mem from 'mem'; import domify from 'doma'; async function fetchDom(url: string): Promise; async function fetchDom(url: string, selector: string): Promise; async function fetchDom(url: string, selector?: string): Promise { const absoluteURL = new URL(url, location.origin).toString(); // Firefox `fetch`es from the content script, so relative URLs fail const response = await fetch(absoluteURL); const dom = domify(await response.text()); if (selector) { return dom.querySelector(selector) ?? undefined; } return dom; } export default mem(fetchDom);