@uxbertlabs/reportly 1.0.35 → 1.0.36
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/features/screenshot.d.ts +1 -9
- package/dist/features/screenshot.d.ts.map +1 -1
- package/dist/index.cjs.js +68 -102
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +68 -102
- package/dist/index.esm.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -15,17 +15,9 @@ declare class Screenshot {
|
|
|
15
15
|
*/
|
|
16
16
|
private waitForStability;
|
|
17
17
|
/**
|
|
18
|
-
* Wait for
|
|
19
|
-
*/
|
|
20
|
-
private waitForAnimations;
|
|
21
|
-
/**
|
|
22
|
-
* Wait for all images to finish loading, including lazy-loaded images
|
|
18
|
+
* Wait for visible images to finish loading (no page scrolling to avoid annotation misalignment)
|
|
23
19
|
*/
|
|
24
20
|
private waitForImages;
|
|
25
|
-
/**
|
|
26
|
-
* Trigger lazy-loading by briefly scrolling through the page
|
|
27
|
-
*/
|
|
28
|
-
private triggerLazyLoading;
|
|
29
21
|
/**
|
|
30
22
|
* Wait for fonts to load
|
|
31
23
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshot.d.ts","sourceRoot":"","sources":["../../src/features/screenshot.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,UAAU,CAAC;AAEvE,cAAM,UAAU;IACd,OAAO,CAAC,iBAAiB,CAAgB;IACzC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,MAAM,CAAkC;gBAEpC,KAAK,CAAC,EAAE,eAAe,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,G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,MAAM,GAAG,IAAI;IAIjC,aAAa,IAAI,MAAM,GAAG,IAAI;IAI9B,KAAK,IAAI,IAAI;CAGd;AAED,eAAe,UAAU,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -9328,77 +9328,46 @@ class Screenshot {
|
|
|
9328
9328
|
* Wait for animations to complete and DOM to stabilize
|
|
9329
9329
|
*/
|
|
9330
9330
|
async waitForStability() {
|
|
9331
|
-
console.log(
|
|
9331
|
+
console.log("⏳ Waiting for page stability...");
|
|
9332
9332
|
// Wait for initial stabilization
|
|
9333
9333
|
await this.wait(this.captureDelay);
|
|
9334
|
-
// Wait for
|
|
9334
|
+
// Wait for currently loading images (NO scrolling to avoid misalignment)
|
|
9335
|
+
// The onclone callback will handle image src copying
|
|
9335
9336
|
await this.waitForImages();
|
|
9336
9337
|
// Wait for fonts to load
|
|
9337
9338
|
await this.waitForFonts();
|
|
9338
|
-
//
|
|
9339
|
-
await this.
|
|
9340
|
-
|
|
9341
|
-
await this.wait(300);
|
|
9342
|
-
console.log('✅ Page stabilized and ready for capture');
|
|
9339
|
+
// Brief wait for final rendering
|
|
9340
|
+
await this.wait(100);
|
|
9341
|
+
console.log("✅ Page stabilized and ready for capture");
|
|
9343
9342
|
}
|
|
9344
9343
|
/**
|
|
9345
|
-
* Wait for
|
|
9346
|
-
*/
|
|
9347
|
-
async waitForAnimations() {
|
|
9348
|
-
// Get all elements with animations or transitions
|
|
9349
|
-
const elements = document.querySelectorAll('*');
|
|
9350
|
-
const animationPromises = [];
|
|
9351
|
-
elements.forEach(element => {
|
|
9352
|
-
const styles = window.getComputedStyle(element);
|
|
9353
|
-
// Check for animations
|
|
9354
|
-
const animationDuration = parseFloat(styles.animationDuration || '0');
|
|
9355
|
-
if (animationDuration > 0) {
|
|
9356
|
-
animationPromises.push(new Promise(resolve => {
|
|
9357
|
-
const timeout = Math.min(animationDuration * 1000, 2000); // Max 2 seconds
|
|
9358
|
-
setTimeout(resolve, timeout);
|
|
9359
|
-
}));
|
|
9360
|
-
}
|
|
9361
|
-
// Check for transitions
|
|
9362
|
-
const transitionDuration = parseFloat(styles.transitionDuration || '0');
|
|
9363
|
-
if (transitionDuration > 0) {
|
|
9364
|
-
animationPromises.push(new Promise(resolve => {
|
|
9365
|
-
const timeout = Math.min(transitionDuration * 1000, 2000); // Max 2 seconds
|
|
9366
|
-
setTimeout(resolve, timeout);
|
|
9367
|
-
}));
|
|
9368
|
-
}
|
|
9369
|
-
});
|
|
9370
|
-
if (animationPromises.length > 0) {
|
|
9371
|
-
console.log(`⏳ Waiting for ${animationPromises.length} animations/transitions...`);
|
|
9372
|
-
await Promise.race([Promise.all(animationPromises), this.wait(2000) // Max 2 seconds total
|
|
9373
|
-
]);
|
|
9374
|
-
}
|
|
9375
|
-
}
|
|
9376
|
-
/**
|
|
9377
|
-
* Wait for all images to finish loading, including lazy-loaded images
|
|
9344
|
+
* Wait for visible images to finish loading (no page scrolling to avoid annotation misalignment)
|
|
9378
9345
|
*/
|
|
9379
9346
|
async waitForImages() {
|
|
9380
|
-
// First, trigger lazy-loading by scrolling through the page
|
|
9381
|
-
await this.triggerLazyLoading();
|
|
9382
|
-
// Now wait for all images to load
|
|
9383
9347
|
const images = Array.from(document.images);
|
|
9384
|
-
|
|
9385
|
-
const
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
|
|
9348
|
+
// Filter to only images that are currently loading
|
|
9349
|
+
const loadingImages = images.filter(img => !img.complete || img.naturalHeight === 0);
|
|
9350
|
+
if (loadingImages.length === 0) {
|
|
9351
|
+
console.log("✅ All visible images already loaded");
|
|
9352
|
+
return;
|
|
9353
|
+
}
|
|
9354
|
+
console.log(`⏳ Waiting for ${loadingImages.length} loading images...`);
|
|
9355
|
+
const imagePromises = loadingImages.map(img => {
|
|
9389
9356
|
return new Promise(resolve => {
|
|
9390
|
-
|
|
9357
|
+
if (img.complete && img.naturalHeight !== 0) {
|
|
9358
|
+
resolve();
|
|
9359
|
+
return;
|
|
9360
|
+
}
|
|
9391
9361
|
const onLoad = () => {
|
|
9392
|
-
|
|
9393
|
-
console.log(`✅ Image ${index + 1} loaded in ${loadTime}ms:`, img.src.substring(0, 80));
|
|
9362
|
+
console.log(`✅ Image loaded`);
|
|
9394
9363
|
resolve();
|
|
9395
9364
|
};
|
|
9396
9365
|
const onError = () => {
|
|
9397
|
-
console.warn(`❌ Image
|
|
9398
|
-
resolve(); // Still resolve to not block
|
|
9366
|
+
console.warn(`❌ Image failed to load`);
|
|
9367
|
+
resolve(); // Still resolve to not block
|
|
9399
9368
|
};
|
|
9400
9369
|
const onTimeout = () => {
|
|
9401
|
-
console.warn(`⏰ Image
|
|
9370
|
+
console.warn(`⏰ Image timed out after 2s`);
|
|
9402
9371
|
resolve();
|
|
9403
9372
|
};
|
|
9404
9373
|
img.addEventListener("load", onLoad, {
|
|
@@ -9407,43 +9376,12 @@ class Screenshot {
|
|
|
9407
9376
|
img.addEventListener("error", onError, {
|
|
9408
9377
|
once: true
|
|
9409
9378
|
});
|
|
9410
|
-
//
|
|
9411
|
-
setTimeout(onTimeout,
|
|
9379
|
+
// Shorter timeout - 2 seconds max
|
|
9380
|
+
setTimeout(onTimeout, 2000);
|
|
9412
9381
|
});
|
|
9413
9382
|
});
|
|
9414
9383
|
await Promise.all(imagePromises);
|
|
9415
|
-
console.log(`✅ All ${
|
|
9416
|
-
}
|
|
9417
|
-
/**
|
|
9418
|
-
* Trigger lazy-loading by briefly scrolling through the page
|
|
9419
|
-
*/
|
|
9420
|
-
async triggerLazyLoading() {
|
|
9421
|
-
const originalScrollY = window.scrollY;
|
|
9422
|
-
const originalScrollX = window.scrollX;
|
|
9423
|
-
const pageHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
|
|
9424
|
-
console.log(`📜 Triggering lazy-load for page height: ${pageHeight}px`);
|
|
9425
|
-
// Scroll through the page in increments to trigger lazy-loading
|
|
9426
|
-
const scrollIncrement = window.innerHeight;
|
|
9427
|
-
const positions = [];
|
|
9428
|
-
// Generate scroll positions (every viewport height)
|
|
9429
|
-
for (let y = 0; y < pageHeight; y += scrollIncrement) {
|
|
9430
|
-
positions.push(y);
|
|
9431
|
-
}
|
|
9432
|
-
// Add final position
|
|
9433
|
-
if (positions[positions.length - 1] < pageHeight) {
|
|
9434
|
-
positions.push(pageHeight);
|
|
9435
|
-
}
|
|
9436
|
-
// Quickly scroll to each position to trigger lazy-load
|
|
9437
|
-
for (const position of positions) {
|
|
9438
|
-
window.scrollTo(0, position);
|
|
9439
|
-
// Small wait to let intersection observers fire
|
|
9440
|
-
await this.wait(50);
|
|
9441
|
-
}
|
|
9442
|
-
// Scroll back to original position
|
|
9443
|
-
window.scrollTo(originalScrollX, originalScrollY);
|
|
9444
|
-
console.log(`✅ Lazy-load triggered, returned to position: ${originalScrollY}px`);
|
|
9445
|
-
// Wait a bit for lazy-loaded images to start loading
|
|
9446
|
-
await this.wait(200);
|
|
9384
|
+
console.log(`✅ All ${loadingImages.length} images processed`);
|
|
9447
9385
|
}
|
|
9448
9386
|
/**
|
|
9449
9387
|
* Wait for fonts to load
|
|
@@ -9504,7 +9442,8 @@ class Screenshot {
|
|
|
9504
9442
|
y: window.scrollY,
|
|
9505
9443
|
// Improved rendering options
|
|
9506
9444
|
backgroundColor: null,
|
|
9507
|
-
imageTimeout:
|
|
9445
|
+
imageTimeout: 15000,
|
|
9446
|
+
// Increased timeout for slow-loading images
|
|
9508
9447
|
removeContainer: true,
|
|
9509
9448
|
scale: window.devicePixelRatio || 1,
|
|
9510
9449
|
onclone: clonedDoc => {
|
|
@@ -9521,11 +9460,25 @@ class Screenshot {
|
|
|
9521
9460
|
// Disable transitions
|
|
9522
9461
|
element.style.transition = "none";
|
|
9523
9462
|
});
|
|
9524
|
-
//
|
|
9525
|
-
const
|
|
9526
|
-
|
|
9527
|
-
|
|
9528
|
-
|
|
9463
|
+
// Process images in the cloned document
|
|
9464
|
+
const originalImages = document.body.querySelectorAll("img");
|
|
9465
|
+
const clonedImages = clonedBody.querySelectorAll("img");
|
|
9466
|
+
clonedImages.forEach((clonedImg, index) => {
|
|
9467
|
+
const originalImg = originalImages[index];
|
|
9468
|
+
if (originalImg) {
|
|
9469
|
+
// Copy the current src from original to ensure it loads
|
|
9470
|
+
clonedImg.src = originalImg.currentSrc || originalImg.src;
|
|
9471
|
+
// Force visibility
|
|
9472
|
+
clonedImg.style.opacity = "1";
|
|
9473
|
+
clonedImg.style.visibility = "visible";
|
|
9474
|
+
clonedImg.style.display = originalImg.style.display || "inline";
|
|
9475
|
+
if (originalImg.width) clonedImg.width = originalImg.width;
|
|
9476
|
+
if (originalImg.height) clonedImg.height = originalImg.height;
|
|
9477
|
+
// Remove lazy loading attributes that might interfere
|
|
9478
|
+
clonedImg.removeAttribute("loading");
|
|
9479
|
+
clonedImg.removeAttribute("data-src");
|
|
9480
|
+
clonedImg.removeAttribute("data-srcset");
|
|
9481
|
+
}
|
|
9529
9482
|
});
|
|
9530
9483
|
},
|
|
9531
9484
|
ignoreElements: element => {
|
|
@@ -9558,8 +9511,6 @@ class Screenshot {
|
|
|
9558
9511
|
}
|
|
9559
9512
|
});
|
|
9560
9513
|
} else {
|
|
9561
|
-
// Wait a bit for scroll to settle
|
|
9562
|
-
await this.wait(1000);
|
|
9563
9514
|
// Capture the full page
|
|
9564
9515
|
canvas = await html2canvas(document.body, {
|
|
9565
9516
|
useCORS: true,
|
|
@@ -9567,7 +9518,8 @@ class Screenshot {
|
|
|
9567
9518
|
logging: false,
|
|
9568
9519
|
// Improved rendering options
|
|
9569
9520
|
backgroundColor: null,
|
|
9570
|
-
imageTimeout:
|
|
9521
|
+
imageTimeout: 15000,
|
|
9522
|
+
// Increased timeout for slow-loading images
|
|
9571
9523
|
removeContainer: true,
|
|
9572
9524
|
scale: window.devicePixelRatio || 1,
|
|
9573
9525
|
onclone: clonedDoc => {
|
|
@@ -9584,11 +9536,25 @@ class Screenshot {
|
|
|
9584
9536
|
// Disable transitions
|
|
9585
9537
|
element.style.transition = "none";
|
|
9586
9538
|
});
|
|
9587
|
-
//
|
|
9588
|
-
const
|
|
9589
|
-
|
|
9590
|
-
|
|
9591
|
-
|
|
9539
|
+
// Process images in the cloned document
|
|
9540
|
+
const originalImages = document.body.querySelectorAll("img");
|
|
9541
|
+
const clonedImages = clonedBody.querySelectorAll("img");
|
|
9542
|
+
clonedImages.forEach((clonedImg, index) => {
|
|
9543
|
+
const originalImg = originalImages[index];
|
|
9544
|
+
if (originalImg) {
|
|
9545
|
+
// Copy the current src from original to ensure it loads
|
|
9546
|
+
clonedImg.src = originalImg.currentSrc || originalImg.src;
|
|
9547
|
+
// Force visibility
|
|
9548
|
+
clonedImg.style.opacity = "1";
|
|
9549
|
+
clonedImg.style.visibility = "visible";
|
|
9550
|
+
clonedImg.style.display = originalImg.style.display || "inline";
|
|
9551
|
+
if (originalImg.width) clonedImg.width = originalImg.width;
|
|
9552
|
+
if (originalImg.height) clonedImg.height = originalImg.height;
|
|
9553
|
+
// Remove lazy loading attributes that might interfere
|
|
9554
|
+
clonedImg.removeAttribute("loading");
|
|
9555
|
+
clonedImg.removeAttribute("data-src");
|
|
9556
|
+
clonedImg.removeAttribute("data-srcset");
|
|
9557
|
+
}
|
|
9592
9558
|
});
|
|
9593
9559
|
},
|
|
9594
9560
|
ignoreElements: element => {
|