checkpoint-cli 0.1.4 → 0.1.5
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/dist/index.js +31 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -266,8 +266,10 @@ function trackingScript() {
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
function resolveAnchor(payload){
|
|
269
|
-
if(!payload||typeof payload!=='object') return null;
|
|
269
|
+
if(!payload||typeof payload!=='object') return {coordFallback:null,strategy:'none',matchedSelector:null};
|
|
270
270
|
var element=null;
|
|
271
|
+
var strategy='none';
|
|
272
|
+
var matchedSelector=null;
|
|
271
273
|
if(Array.isArray(payload.selector_chain)){
|
|
272
274
|
for(var i=0;i<payload.selector_chain.length;i++){
|
|
273
275
|
var candidate=payload.selector_chain[i];
|
|
@@ -276,6 +278,8 @@ function trackingScript() {
|
|
|
276
278
|
var found=document.querySelector(candidate.selector);
|
|
277
279
|
if(found){
|
|
278
280
|
element=found;
|
|
281
|
+
strategy='selector';
|
|
282
|
+
matchedSelector=candidate.selector;
|
|
279
283
|
break;
|
|
280
284
|
}
|
|
281
285
|
}catch(e){}
|
|
@@ -283,18 +287,27 @@ function trackingScript() {
|
|
|
283
287
|
}
|
|
284
288
|
if(!element&&payload.container_hint&&typeof payload.container_hint.selector==='string'){
|
|
285
289
|
try{
|
|
286
|
-
|
|
290
|
+
var containerEl=document.querySelector(payload.container_hint.selector);
|
|
291
|
+
if(containerEl){
|
|
292
|
+
element=containerEl;
|
|
293
|
+
strategy='container';
|
|
294
|
+
matchedSelector=payload.container_hint.selector;
|
|
295
|
+
}
|
|
287
296
|
}catch(e){}
|
|
288
297
|
}
|
|
289
298
|
if(!element){
|
|
290
|
-
|
|
299
|
+
var fpEl=resolveFromFingerprint(payload.dom_fingerprint);
|
|
300
|
+
if(fpEl){
|
|
301
|
+
element=fpEl;
|
|
302
|
+
strategy='fingerprint';
|
|
303
|
+
}
|
|
291
304
|
}
|
|
292
|
-
if(!element) return null;
|
|
305
|
+
if(!element) return {coordFallback:null,strategy:'none',matchedSelector:null};
|
|
293
306
|
var rect=element.getBoundingClientRect();
|
|
294
307
|
var clientX=rect.left+Math.max(1,Math.min(rect.width-1,rect.width*0.5));
|
|
295
308
|
var clientY=rect.top+Math.max(1,Math.min(rect.height-1,rect.height*0.5));
|
|
296
309
|
var metrics=getMetrics();
|
|
297
|
-
return buildCoordFallback(clientX,clientY,metrics);
|
|
310
|
+
return {coordFallback:buildCoordFallback(clientX,clientY,metrics),strategy:strategy,matchedSelector:matchedSelector};
|
|
298
311
|
}
|
|
299
312
|
|
|
300
313
|
function setPickMode(enabled){
|
|
@@ -409,12 +422,22 @@ function trackingScript() {
|
|
|
409
422
|
for(var i=0;i<e.data.items.length;i++){
|
|
410
423
|
var item=e.data.items[i];
|
|
411
424
|
if(!item||typeof item.id!=='string') continue;
|
|
412
|
-
var
|
|
413
|
-
if(coordFallback){
|
|
425
|
+
var result=resolveAnchor(item.anchorPayload);
|
|
426
|
+
if(result.coordFallback){
|
|
414
427
|
positions.push({
|
|
415
428
|
id:item.id,
|
|
416
429
|
found:true,
|
|
417
|
-
|
|
430
|
+
strategy:result.strategy,
|
|
431
|
+
matchedSelector:result.matchedSelector,
|
|
432
|
+
coordFallback:result.coordFallback
|
|
433
|
+
});
|
|
434
|
+
} else {
|
|
435
|
+
positions.push({
|
|
436
|
+
id:item.id,
|
|
437
|
+
found:false,
|
|
438
|
+
strategy:'fallback',
|
|
439
|
+
matchedSelector:null,
|
|
440
|
+
coordFallback:null
|
|
418
441
|
});
|
|
419
442
|
}
|
|
420
443
|
}
|