Sha256: ee1befa3b3ef9a886e5c6751be85103c2066f4a48c412f83448ef0f5aa89eae5

Contents?: true

Size: 460 Bytes

Versions: 46

Compression:

Stored size: 460 Bytes

Contents

async function fetchHTML(url, selector) {
  const response = await fetch(url || window.document.location);
  if (response.ok) {
    const html = await response.text();
    const doc = new DOMParser().parseFromString(html, "text/html");
    return {
      fragment: selector ? doc.querySelector(selector).outerHTML : null,
      title: doc.title,
      doc,
    };
  } else {
    throw new Error(`Error fetching HTML from ${url}`);
  }
}

export { fetchHTML };

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
lookbook-1.0.0.beta.5 app/assets/lookbook/js/helpers/request.js
lookbook-1.0.0.beta.4 app/assets/lookbook/js/helpers/request.js
lookbook-1.0.0.beta.3 app/assets/lookbook/js/helpers/request.js
lookbook-1.0.0.beta.2 app/assets/lookbook/js/helpers/request.js
lookbook-1.0.0.beta.1 app/assets/lookbook/js/helpers/request.js
lookbook-1.0.0.beta.0 app/assets/lookbook/js/helpers/request.js