加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

web页面录屏实现

发布时间:2020-05-11 07:02:25 所属栏目:编程 来源:站长网
导读:副问题#e# 在看到评述后,溘然意识到本身没有提前声名,本文可以说是一篇调研进修文,是我本身感受可行的一套方案,后续会去读读已经开源的一些相同的代码库,补足本身漏掉的一些细节,以是各人可以看成进修文,出产情形慎用。 录屏重现错误场景 假如你的应

window.addEventListener('blur', this.onFormBlur, true); onFormBlur = (event) => { const target = event.target; if (target && target.__flow) { this.records.push({ type: 'blur', target: target.__flow.id, }); } }

媒体元素变革监听

这里指audio和video,相同上面的表单位素,可以监听onplay、onpause变乱、timeupdate、volumechange等等变乱,然后存入records

Canvas画布变革监听

canvas内容变革没有抛失变乱,以是我们可以:

网络canvas元素,按时去更新及时内容 hack一些画画的API,来抛失变乱

canvas监听研究没有很深入,必要进一步深入研究

播放

思绪较量简朴,就是从后端拿到一些信息:

全量快照Virtual DOM

操纵链records

屏幕判别率

doctype

操作这些信息,你就可以起首天生页面DOM,个中包罗过滤script标签,然后建设iframe,append到一个容器中,个中行使一个map来存储DOM

function play(options = {}) { const { container, records = [], snapshot ={} } = options; const { vdom, doctype, clientHeight, clientWidth } = snapshot; this.nodeCache = {}; this.records = records; this.container = container; this.snapshot = snapshot; this.iframe = document.createElement('iframe'); const documentElement = createElement(vdom, (node) => { // 缓存DOM const flowId = node.__flow && node.__flow.id; if (flowId) { this.nodeCache[flowId] = node; } // 过滤script return !(node.nodeType === Node.ELEMENT_NODE && node.tagName.toLowerCase() === 'script'); }); this.iframe.style.width = `${clientWidth}px`; this.iframe.style.height = `${clientHeight}px`; container.appendChild(iframe); const doc = iframe.contentDocument; this.iframeDocument = doc; doc.open(); doc.write(`<!doctype ${doctype}><html><head></head><body></body></html>`); doc.close(); doc.replaceChild(documentElement, doc.documentElement); this.execRecords(); }

function execRecords(preDuration = 0) { const record = this.records.shift(); let node; if (record) { setTimeout(() => { switch (record.type) { // 'childList'、'characterData'、 // 'attributes'、'input'、'checked'、 // 'focus'、'blur'、'play''pause'等变乱的处理赏罚 } this.execRecords(record.duration); }, record.duration - preDuration) } }

上面的duration在上文中省略了,这个你可以按照本身的优化来做播放的流通度,看是多个record作为一帧照旧本来泛起。

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读