通过注入js脚本实现
在chrome浏览器打开直播间,f12打开开发者工具,切换到console,输入以下代码:
var targetNode = document.getElementsByClassName("webcast-chatroom___items")[0];回车后就能实时看到抖音公屏消息了。
// 观察者的选项(要观察哪些突变)
var config = {
attributes: true,
childList: true,
subtree: true
};
// 当观察到突变时执行的回调函数
var callback = function(mutationsList) {
mutationsList.forEach(function(item, index) {
if (item.type == 'childList') {
console.log(item.target.innerText);
} else if (item.type == 'attributes') {
}
});
};
// 创建一个链接到回调函数的观察者实例
var observer = new MutationObserver(callback);
// 开始观察已配置突变的目标节点
observer.observe(targetNode, config);
网友回复