From 7499b05431b27b553e1a81ebd1b73b7b5b9ca5cc Mon Sep 17 00:00:00 2001 From: sylenien Date: Thu, 23 Jun 2022 11:26:02 +0200 Subject: [PATCH] fix(tracker): fix srcset tracking --- tracker/tracker/src/main/modules/img.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tracker/tracker/src/main/modules/img.ts b/tracker/tracker/src/main/modules/img.ts index 1d4fb254a..c8a2f2a64 100644 --- a/tracker/tracker/src/main/modules/img.ts +++ b/tracker/tracker/src/main/modules/img.ts @@ -4,6 +4,7 @@ import { ResourceTiming, SetNodeAttributeURLBased, SetNodeAttribute } from "../. import { hasTag } from "../app/guards.js"; + const PLACEHOLDER_SRC = "https://static.openreplay.com/tracker/placeholder.jpeg"; export default function (app: App): void { @@ -35,20 +36,26 @@ export default function (app: App): void { sendPlaceholder(id, this) } else { app.send(new SetNodeAttributeURLBased(id, 'src', src, app.getBaseHref())); - app.send(new SetNodeAttributeURLBased(id, 'srcset', srcset, app.getBaseHref())); + app.send(new SetNodeAttribute(id, 'srcset', srcset, app.getBaseHref())); } }); const observer = new MutationObserver((mutations) => { for (const mutation of mutations) { - if (mutation.type === "attributes" && mutation.attributeName === "src") { + if (mutation.type === "attributes" && mutation.attributeName === "src" || mutation.attributeName === "srcset") { const target = (mutation.target as HTMLImageElement); const id = app.nodes.getID(target); if (id === undefined) { return; } - const src = target.src; - app.send(new SetNodeAttributeURLBased(id, 'src', src, app.getBaseHref())); + if (mutation.attributeName === "src") { + const src = target.src; + app.send(new SetNodeAttributeURLBased(id, 'src', src, app.getBaseHref())); + } + if (mutation.attributeName === "srcset") { + const srcset = target.srcset; + app.send(new SetNodeAttribute(id, 'srcset', srcset)); + } } } });