* Canvas downloads the intercepted content * @param canvas
(canvas, title, video)
| 75 | * @param canvas |
| 76 | */ |
| 77 | download(canvas, title, video) { |
| 78 | title = title || "videoCapturer_" + Date.now(); |
| 79 | |
| 80 | try { |
| 81 | /** |
| 82 | * Try copying to clipboard |
| 83 | * Note that some browsers do not support writing 'image/jpeg' type data to the clipboard. Image/jpg can, but the result of toBlob will be png data. |
| 84 | * So here is a new 'image/png' to try to copy to the clipboard, instead of putting setClipboard(blob) in the try below |
| 85 | * In addition, since the automatic downloading of the screenshot below will cause the page to be out of focus, it will also cause the copy to the clipboard to fail, so here we copy it to the clipboard first and then download it. |
| 86 | */ |
| 87 | canvas.toBlob( |
| 88 | function (blob) { |
| 89 | setClipboard(blob); |
| 90 | }, |
| 91 | "image/png", |
| 92 | 0.99 |
| 93 | ); |
| 94 | } catch (e) { |
| 95 | console.error("无法将截图复制到剪贴板。", e); |
| 96 | } |
| 97 | |
| 98 | try { |
| 99 | canvas.toBlob( |
| 100 | function (blob) { |
| 101 | const el = document.createElement("a"); |
| 102 | el.download = `${title}.jpg`; |
| 103 | el.href = URL.createObjectURL(blob); |
| 104 | el.click(); |
| 105 | }, |
| 106 | "image/jpeg", |
| 107 | 0.99 |
| 108 | ); |
| 109 | } catch (e) { |
| 110 | videoCapturer.preview(canvas, title); |
| 111 | console.error( |
| 112 | "The video source is restricted by the CORS logo and screenshots cannot be downloaded directly. See:\n https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" |
| 113 | ); |
| 114 | console.error(video, e); |
| 115 | } |
| 116 | }, |
| 117 | }; |
| 118 | |
| 119 | export default videoCapturer; |
nothing calls this directly
no test coverage detected