@checksum-ai/runtime 1.1.53-beta → 1.1.54-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/checksumlib.js CHANGED
@@ -34267,6 +34267,7 @@
34267
34267
  this.singleSelection = true;
34268
34268
  this.subDocumentInspector = null;
34269
34269
  this.listening = false;
34270
+ this.locatorCache = InspectedElementCache.getInstance();
34270
34271
  this.onMouseOut = /* @__PURE__ */ __name((event) => {
34271
34272
  elementHighlighter.clearHighlights();
34272
34273
  }, "onMouseOut");
@@ -34302,13 +34303,7 @@
34302
34303
  capture: true
34303
34304
  });
34304
34305
  }
34305
- const { locator, selector, parentFramesSelectors } = await this.playwrightElementSelectorGenerator.getSelectorAndLocator(targetElement).catch((error) => {
34306
- return {
34307
- locator: "",
34308
- selector: "",
34309
- parentFramesSelectors: []
34310
- };
34311
- });
34306
+ const { locator, selector, parentFramesSelectors, locatorRrwebId } = await this.getInspectedElementSelection(targetElement);
34312
34307
  elementHighlighter.highlightElement(targetElement, {
34313
34308
  text: locator.replace("frameLocator('iframe').", ""),
34314
34309
  textPosition: "below",
@@ -34317,15 +34312,17 @@
34317
34312
  classNames: ["element-inspector-ignore"],
34318
34313
  renderDocument: this.getRenderDocument(this.defaultView)
34319
34314
  });
34320
- const elementByLocator = await this.playwrightElementSelectorGenerator.selector(selector, parentFramesSelectors).catch(() => targetElement);
34321
- if (elementByLocator !== target) {
34322
- elementHighlighter.highlightElement(elementByLocator, {
34323
- // highlightStyle: { outlineColor: "blue" },
34324
- clear: false,
34325
- pointerEvents: "none",
34326
- classNames: ["element-inspector-ignore"],
34327
- renderDocument: this.getRenderDocument(this.defaultView)
34328
- });
34315
+ if (locatorRrwebId) {
34316
+ const element = window.checksum.timeMachine.sessionReplayer.getNodeById(locatorRrwebId);
34317
+ if (element) {
34318
+ elementHighlighter.highlightElement(element, {
34319
+ // highlightStyle: { outlineColor: "blue" },
34320
+ clear: false,
34321
+ pointerEvents: "none",
34322
+ classNames: ["element-inspector-ignore"],
34323
+ renderDocument: this.getRenderDocument(this.defaultView)
34324
+ });
34325
+ }
34329
34326
  }
34330
34327
  this.hoveredElement = targetElement;
34331
34328
  this.hoveredElementSelection = { locator, selector, parentFramesSelectors };
@@ -34366,7 +34363,10 @@
34366
34363
  topLevelInspector: this.topLevelInspector ?? this,
34367
34364
  getRenderDocument: this.getRenderDocument
34368
34365
  });
34369
- this.subDocumentInspector.start(this.singleSelection);
34366
+ this.subDocumentInspector.start({
34367
+ singleSelection: this.singleSelection,
34368
+ timestamp: this.currentTimestamp
34369
+ });
34370
34370
  return true;
34371
34371
  }, "handleSubDocument");
34372
34372
  this.stopSubDocumentInspector = /* @__PURE__ */ __name((clean) => {
@@ -34387,8 +34387,15 @@
34387
34387
  getDefaultView() {
34388
34388
  return this.rootDocument.nodeType === Node.DOCUMENT_NODE ? this.rootDocument.defaultView : window;
34389
34389
  }
34390
- start(singleSelection = true) {
34390
+ start({
34391
+ singleSelection,
34392
+ timestamp
34393
+ } = {
34394
+ singleSelection: true
34395
+ }) {
34391
34396
  this.singleSelection = singleSelection;
34397
+ this.locatorCache.setTimestamp(timestamp);
34398
+ this.currentTimestamp = timestamp;
34392
34399
  this.stop();
34393
34400
  this.cleanSelection();
34394
34401
  this.rootDocument.addEventListener("mouseover", this.onMouseOver);
@@ -34409,6 +34416,7 @@
34409
34416
  capture: true
34410
34417
  });
34411
34418
  }
34419
+ this.currentTimestamp = void 0;
34412
34420
  this.hoveredElement = null;
34413
34421
  this.wasHoveredElementSelected = false;
34414
34422
  this.rootDocument.removeEventListener("mouseover", this.onMouseOver);
@@ -34430,7 +34438,78 @@
34430
34438
  this.cleanSelection();
34431
34439
  return selected;
34432
34440
  }
34441
+ /**
34442
+ * Gets selection data for element.
34443
+ * Tried to fetch from cache first, if not found, generates new data, saves it to cache and returns it.
34444
+ */
34445
+ async getInspectedElementSelection(element) {
34446
+ let cache = this.locatorCache.getCachedLocatorForElement(element);
34447
+ if (!cache) {
34448
+ const { locator, selector, parentFramesSelectors } = await this.playwrightElementSelectorGenerator.getSelectorAndLocator(element).catch((error) => {
34449
+ return {
34450
+ locator: "",
34451
+ selector: "",
34452
+ parentFramesSelectors: []
34453
+ };
34454
+ });
34455
+ const locatorElement = await this.playwrightElementSelectorGenerator.selector(selector, parentFramesSelectors).catch(() => element);
34456
+ const locatorRrwebId = locatorElement !== element ? getNodeRrwebId(locatorElement) : void 0;
34457
+ cache = {
34458
+ locator,
34459
+ selector,
34460
+ parentFramesSelectors,
34461
+ locatorRrwebId
34462
+ };
34463
+ this.locatorCache.setCachedLocatorForElement(element, cache);
34464
+ }
34465
+ return cache;
34466
+ }
34433
34467
  };
34468
+ var InspectedElementCache = class _InspectedElementCache {
34469
+ constructor() {
34470
+ this.locatorCache = /* @__PURE__ */ new Map();
34471
+ }
34472
+ static {
34473
+ __name(this, "InspectedElementCache");
34474
+ }
34475
+ // key - rrwebid_timestamp
34476
+ static getInstance() {
34477
+ if (!_InspectedElementCache.instance) {
34478
+ _InspectedElementCache.instance = new _InspectedElementCache();
34479
+ }
34480
+ return _InspectedElementCache.instance;
34481
+ }
34482
+ setTimestamp(timestamp) {
34483
+ this.currentTimestamp = timestamp;
34484
+ }
34485
+ getCachedLocatorForElement(element) {
34486
+ try {
34487
+ if (!this.currentTimestamp) {
34488
+ return;
34489
+ }
34490
+ return this.locatorCache.get(this.getKeyForElement(element));
34491
+ } catch (e2) {
34492
+ return;
34493
+ }
34494
+ }
34495
+ setCachedLocatorForElement(element, cache) {
34496
+ if (!this.currentTimestamp) {
34497
+ return;
34498
+ }
34499
+ this.locatorCache.set(this.getKeyForElement(element), cache);
34500
+ }
34501
+ getKeyForElement(element) {
34502
+ const rrwebId = getNodeRrwebId(element);
34503
+ if (!rrwebId) {
34504
+ throw new Error("Can't find rrwebId for element");
34505
+ }
34506
+ return `${rrwebId}_${this.currentTimestamp}`;
34507
+ }
34508
+ };
34509
+ function getNodeRrwebId(node2) {
34510
+ return window.checksum.timeMachine.sessionReplayer.getMeta(node2)?.id;
34511
+ }
34512
+ __name(getNodeRrwebId, "getNodeRrwebId");
34434
34513
 
34435
34514
  // src/lib/test-generator/assertions-observer/keybindings-manager.ts
34436
34515
  var import_mousetrap = __toESM(require_mousetrap());
@@ -36216,7 +36295,11 @@ ${data.locator}`
36216
36295
  setSendRecordedSteps(sendRecordedSteps) {
36217
36296
  this.sendRecordedSteps = sendRecordedSteps;
36218
36297
  }
36219
- startInspector(singleSelection = true, rootDocument) {
36298
+ startInspector({
36299
+ singleSelection = true,
36300
+ rootDocument,
36301
+ timestamp
36302
+ } = {}) {
36220
36303
  this.stopInspector();
36221
36304
  const getRenderDocument = /* @__PURE__ */ __name((defaultView) => {
36222
36305
  return defaultView.top.document.querySelector(
@@ -36227,7 +36310,7 @@ ${data.locator}`
36227
36310
  rootDocument: rootDocument ?? this.getRRwebReplayerDocument(),
36228
36311
  getRenderDocument
36229
36312
  });
36230
- this.elementInspector.start(singleSelection);
36313
+ this.elementInspector.start({ singleSelection, timestamp });
36231
36314
  }
36232
36315
  getRRwebReplayerDocument() {
36233
36316
  return document.querySelector(".replayer-wrapper > iframe").contentDocument;