@lambdatest/smartui-cli 3.0.3 → 3.0.4
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/dom-serializer.js +26 -23
- package/dist/index.cjs +22 -4
- package/package.json +1 -1
package/dist/dom-serializer.js
CHANGED
|
@@ -332,32 +332,35 @@
|
|
|
332
332
|
for (let video of dom.querySelectorAll('video')) {
|
|
333
333
|
let videoId = video.getAttribute('data-smartui-element-id');
|
|
334
334
|
let cloneEl = clone.querySelector(`[data-smartui-element-id="${videoId}"]`);
|
|
335
|
-
// if the video already has a poster image, no work for us to do
|
|
336
|
-
if (video.getAttribute('poster')) {
|
|
337
|
-
cloneEl.removeAttribute('src');
|
|
338
|
-
continue;
|
|
339
|
-
}
|
|
340
|
-
let canvas = document.createElement('canvas');
|
|
341
|
-
let width = canvas.width = video.videoWidth;
|
|
342
|
-
let height = canvas.height = video.videoHeight;
|
|
343
|
-
let dataUrl;
|
|
344
|
-
canvas.getContext('2d').drawImage(video, 0, 0, width, height);
|
|
345
|
-
try {
|
|
346
|
-
dataUrl = canvas.toDataURL();
|
|
347
|
-
} catch (e) {
|
|
348
|
-
warnings.add(`data-smartui-element-id="${videoId}" : ${e.toString()}`);
|
|
349
|
-
}
|
|
350
335
|
|
|
351
|
-
//
|
|
352
|
-
|
|
336
|
+
// remove video sources
|
|
337
|
+
cloneEl.removeAttribute('src');
|
|
338
|
+
const sourceEls = cloneEl.querySelectorAll('source');
|
|
339
|
+
if (sourceEls.length) sourceEls.forEach((sourceEl) => sourceEl.remove());
|
|
340
|
+
|
|
341
|
+
// if the video doesn't have a poster image
|
|
342
|
+
if (!video.getAttribute('poster')) {
|
|
343
|
+
let canvas = document.createElement('canvas');
|
|
344
|
+
let width = canvas.width = video.videoWidth;
|
|
345
|
+
let height = canvas.height = video.videoHeight;
|
|
346
|
+
let dataUrl;
|
|
347
|
+
canvas.getContext('2d').drawImage(video, 0, 0, width, height);
|
|
348
|
+
try {
|
|
349
|
+
dataUrl = canvas.toDataURL();
|
|
350
|
+
} catch (e) {
|
|
351
|
+
warnings.add(`data-smartui-element-id="${videoId}" : ${e.toString()}`);
|
|
352
|
+
}
|
|
353
353
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
// resources.add(resource);
|
|
354
|
+
// if the canvas produces a blank image, skip
|
|
355
|
+
if (!dataUrl || dataUrl === 'data:,') continue;
|
|
357
356
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
357
|
+
// create a resource from the serialized data url
|
|
358
|
+
let resource = resourceFromDataURL(videoId, dataUrl);
|
|
359
|
+
resources.add(resource);
|
|
360
|
+
|
|
361
|
+
// set poster attribute to resource url to avoid making a real request
|
|
362
|
+
cloneEl.setAttribute('poster', resource.url);
|
|
363
|
+
}
|
|
361
364
|
}
|
|
362
365
|
}
|
|
363
366
|
|
package/dist/index.cjs
CHANGED
|
@@ -433,6 +433,9 @@ var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function*
|
|
|
433
433
|
const requestUrl = request.url();
|
|
434
434
|
const requestHostname = new URL(requestUrl).hostname;
|
|
435
435
|
try {
|
|
436
|
+
if (/\.(mp3|mp4|wav|ogg|webm)$/i.test(request.url())) {
|
|
437
|
+
throw new Error("resource type mp3/mp4/wav/ogg/webm");
|
|
438
|
+
}
|
|
436
439
|
ctx.config.allowedHostnames.push(new URL(snapshot.url).hostname);
|
|
437
440
|
if (ctx.config.enableJavaScript)
|
|
438
441
|
ALLOWED_RESOURCES.push("script");
|
|
@@ -539,14 +542,21 @@ var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function*
|
|
|
539
542
|
yield page.setViewportSize({ width: viewport.width, height: viewport.height || MIN_VIEWPORT_HEIGHT });
|
|
540
543
|
ctx.log.debug(`Page resized to ${viewport.width}x${viewport.height || MIN_VIEWPORT_HEIGHT}`);
|
|
541
544
|
if (!navigated) {
|
|
542
|
-
yield page.goto(snapshot.url);
|
|
545
|
+
yield page.goto(snapshot.url, { waitUntil: "domcontentloaded" });
|
|
546
|
+
yield new Promise((r) => setTimeout(r, 1250));
|
|
547
|
+
if (ctx.config.waitForTimeout)
|
|
548
|
+
yield page.waitForTimeout(ctx.config.waitForTimeout);
|
|
543
549
|
navigated = true;
|
|
544
550
|
ctx.log.debug(`Navigated to ${snapshot.url}`);
|
|
545
551
|
}
|
|
546
552
|
if (fullPage)
|
|
547
553
|
yield page.evaluate(scrollToBottomAndBackToTop);
|
|
548
|
-
|
|
549
|
-
|
|
554
|
+
try {
|
|
555
|
+
yield page.waitForLoadState("networkidle", { timeout: 5e3 });
|
|
556
|
+
ctx.log.debug("Network idle 500ms");
|
|
557
|
+
} catch (error) {
|
|
558
|
+
ctx.log.debug(`Network idle failed due to ${error}`);
|
|
559
|
+
}
|
|
550
560
|
if (processedOptions.element) {
|
|
551
561
|
let l = yield page.locator(processedOptions.element).all();
|
|
552
562
|
if (l.length === 0) {
|
|
@@ -580,6 +590,14 @@ var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function*
|
|
|
580
590
|
}
|
|
581
591
|
yield page.close();
|
|
582
592
|
yield context.close();
|
|
593
|
+
if (snapshot.dom.resources.length) {
|
|
594
|
+
for (let resource of snapshot.dom.resources) {
|
|
595
|
+
cache[resource.url] = {
|
|
596
|
+
body: resource.content,
|
|
597
|
+
type: resource.mimetype
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
}
|
|
583
601
|
return {
|
|
584
602
|
processedSnapshot: {
|
|
585
603
|
name: snapshot.name,
|
|
@@ -980,7 +998,7 @@ var auth_default = (ctx) => {
|
|
|
980
998
|
};
|
|
981
999
|
|
|
982
1000
|
// package.json
|
|
983
|
-
var version = "3.0.
|
|
1001
|
+
var version = "3.0.4";
|
|
984
1002
|
var package_default = {
|
|
985
1003
|
name: "@lambdatest/smartui-cli",
|
|
986
1004
|
version,
|