Skip to content

Commit 98ec402

Browse files
author
likai
committed
feat: 扩展useCORS参数
1 parent ca5a712 commit 98ec402

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/lib/type/ComponentType.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export type screenShotType = {
104104
imgSrc?: string; // 截图内容,默认为false
105105
loadCrossImg?: boolean; // 加载跨域图片状态
106106
proxyUrl?: string; // 代理服务器地址
107+
useCORS?: boolean; // 是否启用跨域
107108
screenShotDom?: HTMLElement | HTMLDivElement | HTMLCanvasElement; // 需要进行截图的容器
108109
cropBoxInfo?: { x: number; y: number; w: number; h: number }; // 是否加载默认的裁剪框
109110
wrcReplyTime?: number; // webrtc捕捉屏幕响应时间,默认为500ms

src/main.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export default class ScreenShot {
120120
// 鼠标是否在裁剪框内
121121
private mouseInsideCropBox = false;
122122
private proxyUrl: undefined | string = undefined;
123+
private useCORS = false;
123124
private drawStatus = false;
124125
// webrtc模式下的屏幕流数据
125126
private captureStream: MediaStream | null = null;
@@ -266,7 +267,8 @@ export default class ScreenShot {
266267
// html2canvas截屏
267268
html2canvas(this.screenShotDom ? this.screenShotDom : document.body, {
268269
onclone: this.loadCrossImg ? drawCrossImg : undefined,
269-
proxy: this.proxyUrl
270+
proxy: this.proxyUrl,
271+
useCORS: this.useCORS
270272
})
271273
.then(canvas => {
272274
// 装载截图的dom为null则退出
@@ -1018,6 +1020,9 @@ export default class ScreenShot {
10181020
if (options?.proxyUrl) {
10191021
this.proxyUrl = options.proxyUrl;
10201022
}
1023+
if (options?.useCORS) {
1024+
this.useCORS = options.useCORS;
1025+
}
10211026
// 设置截图容器的位置信息
10221027
if (options?.position != null) {
10231028
if (options.position?.top != null) {

0 commit comments

Comments
 (0)