#5368·cheerio

fromURL doesn't seem to automatically set the document's URL as expected

Author: tomjbradleyCreated Jul 25, 2026Updated Aug 3, 2026

On this page it mentions that the document URL, for the purpose of resolving relative hrefs, should be set automatically when using fromURL, however this doesn't appear to be the case.

For instance, the following code outputs "/docs/intro" instead of "https://cheerio.js.org/docs/intro":

javascript
const cheerio = require("cheerio");

(async () => {
    const $ = await cheerio.fromURL("https://cheerio.js.org/");

    const href = $("a:contains(Learn)").prop("href");

    console.log(href);
})();