Skip to content

Commit 8a6eb02

Browse files
committed
feat: Screencast is replaced by snapDOM from html2canvas
1 parent 076f1f5 commit 8a6eb02

File tree

4 files changed

+8
-24
lines changed

4 files changed

+8
-24
lines changed

src/client/cdp/common/constant.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ export const DEVTOOL_OVERLAY = '__devtools-overlay__';
22

33
export const DEVTOOL_STYLESHEET = '__devtools-stylesheet__';
44

5-
export const HTML_TO_CANVAS = 'html2canvas-container';
6-
7-
export const IGNORE_NODE = [DEVTOOL_OVERLAY, DEVTOOL_STYLESHEET, HTML_TO_CANVAS];
5+
export const IGNORE_NODE = [DEVTOOL_OVERLAY, DEVTOOL_STYLESHEET];

src/client/cdp/domain/overlay.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ export default class Overlay extends BaseDomain {
193193

194194
containerBox.className = DEVTOOL_OVERLAY;
195195
containerBox.id = DEVTOOL_OVERLAY;
196+
containerBox.setAttribute('data-capture', 'exclude');
196197
document.body.appendChild(containerBox);
197198

198199
this.highlightBox = { containerBox, contentBox, marginBox, tooltipsBox };

src/client/cdp/domain/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default class Page extends BaseDomain {
8080

8181
captureScreen();
8282

83-
this.intervalTimer = setInterval(captureScreen, 2000);
83+
this.intervalTimer = setInterval(captureScreen, 1000);
8484
}
8585

8686
stopScreencast() {

src/client/cdp/domain/screen-preview.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,20 @@
11
import throttle from 'lodash.throttle';
2-
import { isMatches, isMobile, loadScript } from '../common/utils';
3-
import { DEVTOOL_OVERLAY } from '../common/constant';
2+
import { isMobile, loadScript } from '../common/utils';
43
import BaseDomain from './domain';
54
import { Event } from './protocol';
65

76
export default class ScreenPreview extends BaseDomain {
87
namespace = 'ScreenPreview';
98

109
static captureScreen() {
11-
const renderScreen = () => window.html2canvas(document.body, {
12-
allowTaint: true,
13-
backgroundColor: null,
14-
useCORS: true,
15-
imageTimeout: 10000,
16-
scale: 1,
17-
logging: false,
18-
ignoreElements: (element) => {
19-
if (!element?.style) return false;
20-
const { display, opacity, visibility } = element.style;
21-
return isMatches(element, `.${DEVTOOL_OVERLAY}`) ||
22-
display === 'none' ||
23-
opacity === 0 ||
24-
visibility === 'hidden';
25-
}
26-
}).then(canvas => canvas.toDataURL('image/jpeg'));
10+
const renderScreen = () => window.snapdom.toCanvas(document.body)
11+
.then(canvas => canvas.toDataURL('image/jpeg'));
2712

28-
if (window.html2canvas) {
13+
if (window.snapdom) {
2914
return renderScreen();
3015
}
3116

32-
return loadScript('https://unpkg.com/html2canvas@1.4.1/dist/html2canvas.min.js').then(renderScreen);
17+
return loadScript('https://unpkg.com/@zumer/snapdom@1.8.0/dist/snapdom.min.js').then(renderScreen);
3318
}
3419

3520
/**

0 commit comments

Comments
 (0)