Skip to content

Commit daaeca9

Browse files
author
Abhishek Bindra
committed
feat(fingerprint): integrate htmlHash into DqElement toJSON
Compute htmlHash from element.outerHTML before truncation. Added to toJSON() output alongside selector, source, xpath, etc. Handles null element (spec/virtualNode) case gracefully.
1 parent 59b8555 commit daaeca9

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

lib/core/utils/dq-element.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import cache from '../base/cache';
77
import memoize from './memoize';
88
import getNodeAttributes from './get-node-attributes';
99
import VirtualNode from '../../core/base/virtual-node/virtual-node';
10+
import computeFingerprintHash from './fingerprint';
1011

1112
const CACHE_KEY = 'DqElm.RunOptions';
1213

@@ -341,6 +342,15 @@ const DqElement = memoize(function DqElement(elm, options, spec) {
341342
this.nodeIndexes = [this._virtualNode.nodeIndex];
342343
}
343344

345+
// [a11y-core]: compute htmlHash before truncation
346+
try {
347+
this._htmlHash = this._element
348+
? computeFingerprintHash(this._element.outerHTML)
349+
: null;
350+
} catch {
351+
this._htmlHash = null;
352+
}
353+
344354
/**
345355
* The generated HTML source code of the element
346356
* @type {String|null}
@@ -411,7 +421,8 @@ DqElement.prototype = {
411421
xpath: this.xpath,
412422
ancestry: this.ancestry,
413423
nodeIndexes: this.nodeIndexes,
414-
fromFrame: this.fromFrame
424+
fromFrame: this.fromFrame,
425+
htmlHash: this._htmlHash
415426
};
416427
if (this._includeElementInJson) {
417428
spec.element = this._element;

0 commit comments

Comments
 (0)