Commit 9085e70b authored by Marco Bonardo's avatar Marco Bonardo
Browse files

Bug 1759548 - MR2-1988 - Support some kind of lazy loading of images in...

Bug 1759548 - MR2-1988 - Support some kind of lazy loading of images in schema.org definitions. r=mossop

Differential Revision: https://phabricator.services.mozilla.com/D140995
parent 5c45cee9
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -163,11 +163,20 @@ function parseMicrodataProp(propElement) {
    case "audio":
    case "embed":
    case "iframe":
    case "img":
    case "source":
    case "track":
    case "video":
      return parseUrl(propElement, "src");
    case "img":
      // Some pages may be using a lazy loading approach to images, putting a
      // temporary image in "src" while the real image is in a differently
      // named attribute. So far we found "content" and "data-src" are common
      // names for that attribute.
      return (
        parseUrl(propElement, "content") ||
        parseUrl(propElement, "data-src") ||
        parseUrl(propElement, "src")
      );
    case "object":
      return parseUrl(propElement, "data");
    case "a":
+29 −0
Original line number Diff line number Diff line
@@ -162,3 +162,32 @@ add_task(async function test_json_ld_parse() {
    ]
  );
});

add_task(async function test_microdata_lazy_image() {
  await verifyItems(
    `
      <!DOCTYPE html>
      <html>
      <head>
      <title>Product Info 1</title>
      </head>
      <body itemprop="badprop">
        <div itemscope itemtype="https://schema.org/Product">
          <img itemprop="image" src="lazy-load.gif" data-src="bon-echo-microwave-17in.jpg" />
          <a href="microwave.html" itemprop="url">
            <span itemprop="name">Bon Echo Microwave</span>
          </a>
        </div>
      </body>
      </html>
    `,
    [
      {
        "@type": "Product",
        image: BASE_URL + "/bon-echo-microwave-17in.jpg",
        url: BASE_URL + "/microwave.html",
        name: "Bon Echo Microwave",
      },
    ]
  );
});