Commit eaf7c61f authored by aiduck's avatar aiduck

添加黑名单

parent 286001bd
{ {
"name": "@tuia/rip", "name": "@tuia/rip",
"version": "1.2.1", "version": "1.2.2-beta",
"description": "Tools for user behavior recording and playback based on rrweb", "description": "Tools for user behavior recording and playback based on rrweb",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
......
...@@ -7,7 +7,9 @@ class Monitor { ...@@ -7,7 +7,9 @@ class Monitor {
rrwebHandler = null; rrwebHandler = null;
initialized = false; initialized = false;
listenedRoute = false; listenedRoute = false;
isBlockingFlag = false;
tracksWorker = new TracksWorker(); tracksWorker = new TracksWorker();
_blackList = [];
constructor() { constructor() {
(() => { (() => {
var lastTime = performance.now(); var lastTime = performance.now();
...@@ -44,16 +46,19 @@ class Monitor { ...@@ -44,16 +46,19 @@ class Monitor {
return false; return false;
} }
setInterval(() => { setInterval(() => {
if (isBlocking(fpsList, 30, 8)) { if (isBlocking(fpsList, 20, 4)) {
// this.stop(); // this.stop();
isBlockingFlag = true;
} }
fpsList = []; fpsList = [];
}, 10000); }, 5000);
} }
init({ system, userIdentifier, host = [], env = "prod", log = false, path = "/" }) { init({ system, userIdentifier, host = [], env = "prod", log = false, path = "/", blackList = [] }) {
let protocol = document.location.protocol; let protocol = document.location.protocol;
let realHost = window.location.host; let realHost = window.location.host;
_blackList = blackList;
console.log('黑名单', _blackList);
if (!system || !userIdentifier || host.length > 0) { if (!system || !userIdentifier || host.length > 0) {
console.log("system,userIdentifier,host是必传的"); console.log("system,userIdentifier,host是必传的");
} }
...@@ -70,8 +75,13 @@ class Monitor { ...@@ -70,8 +75,13 @@ class Monitor {
protocol, protocol,
}, },
}); });
if(_blackList && _blackList.includes(path)) {
this.stop();
console.log('改页面不支持用户行为监控');
} else {
this.initialized = true; this.initialized = true;
this.record(); this.record();
}
} else { } else {
this.reset({ userIdentifier }); this.reset({ userIdentifier });
} }
...@@ -104,7 +114,16 @@ class Monitor { ...@@ -104,7 +114,16 @@ class Monitor {
console.log("开始录制"); console.log("开始录制");
this.rrwebHandler = rrweb.record({ this.rrwebHandler = rrweb.record({
emit: event => { emit: event => {
this.tracksWorker.postMessage({ type: "record", payload: { ...event, fps: fpsList.length ? fpsList.slice(fpsList.length - 1)[0] : 0 } }); this.tracksWorker.postMessage(
{
type: "record",
payload: {
...event,
fps: fpsList.length ? fpsList.slice(fpsList.length - 1)[0] : 0,
isBlockingFlag
}
});
isBlockingFlag = 0;
}, },
}); });
} }
...@@ -119,6 +138,10 @@ class Monitor { ...@@ -119,6 +138,10 @@ class Monitor {
window.addEventListener("hashchange", () => { window.addEventListener("hashchange", () => {
// 忽略hash后的query // 忽略hash后的query
let hash = getPureHash(location.hash); let hash = getPureHash(location.hash);
if(_blackList && _blackList.includes(hash)) {
this.stop();
console.log('改页面不支持用户行为监控');
}
if (hash === preHash) return console.log("hash query 无变化,no reset"); if (hash === preHash) return console.log("hash query 无变化,no reset");
preHash = hash; preHash = hash;
//防抖,防止无效的频繁触发 //防抖,防止无效的频繁触发
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment