
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
wall_sdk 是一款前端监听系统(SDK),负责收集前端信息,包括 ajax, fetch ,error,用户行为等。监控服务还包括 wall 监控系统的服务端wall-server
项目整体的部署流程请参考-部署
vue react引入 sdk 放到所有 js 资源之前
npm install wall_sdk --save
import Wall from 'wall_sdk'
Wall.init({
project_id: xxxxxxxxxx, // 项目标识
isTest: false,
frequency: 1,
});
具体 init 初始化参考 options
Vue 2.x 中我们应该这样捕获全局异常:
Vue.config.errorHandler = function(err, vm, info) {
let {
message, // 异常信息
name, // 异常名称
script, // 异常脚本url
line, // 异常行号
column, // 异常列号
stack // 异常堆栈信息
} = err;
WALL.createCustomErrorEvent({
message: 'vue异常',
content: {
message,
name,
script,
line,
column,
stack
}
});
// vm为抛出异常的 Vue 实例
// info为 Vue 特定的错误信息,比如错误所在的生命周期钩子
};
React 16.x 版本中引入了 Error Boundary:
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
componentDidCatch(error, info) {
this.setState({ hasError: true });
// 将异常信息上报给服务器
WALL.createCustomErrorEvent({
message: 'react异常',
content: info
});
}
render() {
if (this.state.hasError) {
return '出错了';
}
return this.props.children;
}
}
进入目录安装依赖:
npm i 或者 yarn install
开发& 测试:
npm run start
打开 http://localhost:8001
index.html 中包含各种类型错误,可以调试
打包
npm run build
wallEvent 含义: 错误的发生,用户的行为, 资源的加载,统称为 事件,即为 event,event 中包含事件的详细信息。
可以参考 wallEvent-demo
interface EventInterface {
type: keyof EventType // wallEvent.type
info: InfoInterface; // 上报的具体信息内容
key?: string; // 每个event 都有自己的 唯一key
version?: number; // sdk 版本
createTime?: number; // event创建时间
options?: OptionsInterface; // wall 初始化信息
userId?: string; // 用户id
uuid?: string; // 设备id
}
wallEvent 的类型-type 如下, 每个类型都会触发信息上报
type EventType = {
ERROR_XHR: 'ERROR_XHR', // xhrerror
ERROR_LINK: 'ERROR_LINK', //静态资源 link加载错误
ERROR_IMAGE: 'ERROR_IMAGE', //静态资源 img
ERROR_SCRIPT: 'ERROR_SCRIPT', // 静态资源 script加载错误
ERROR_CUSTOM: 'ERROR_CUSTOM', // 用户自定义错误
ERROR_RUNTIME: 'ERROR_RUNTIME', // 普通错误
ERROR_PROMISE: 'ERROR_PROMISE', // peomise error
ERROR_CONSOLE: 'ERROR_CONSOLE', // console.error
BEHAVIOR_XHR: 'BEHAVIOR_XHR', // 用户请求
BEHAVIOR_XPATH: 'BEHAVIOR_XPATH', // 用户点击路径
BEHAVIOR_FETCH: 'BEHAVIOR_FETCH', // 用户请求
BEHAVIOR_CUSTOM: 'BEHAVIOR_CUSTOM', // 用户自定行为
BEHAVIOR_URLCHANGE: 'BEHAVIOR_URLCHANGE', // 路由改变
DURATION: 'DURATION', // 用户停留时间
RESCOURCES: 'RESCOURCES'
};
interface OptionsInterface {
project_id: string; // 项目id
origin: string; // server 地址
frequency: number;
isTest?: boolean;
userId?: string;
}
| name | describe | explain |
|---|---|---|
| project_id | 项目 id | 必填 |
| origin | 后台上报服务地址 | 必填-端口默认为 9090 |
| frequency | 上报频率 | 非必填 -范围为 0-1, 默认为 1 |
| isTest | 是否是测试环境 | 非必填 - 默认为 false-测试模式下打点数据仅供控制台打印浏览, 不会上传到系统中 |
| userId | 业务用户 id | 非必填 - 默认为 系统自动生成 |
| fn | describe | explain |
|---|---|---|
| createCustomErrorEvent(message: string, content: Object) | 自定义错误 | message: 错误信息标题,content: {}错误信息内容 |
| createCustomBehaviorEvent(behaviorType: string,behaviorResult: object,message: string) | 自定义行为 | message: 错误信息标题,behaviorType:自定义行为类型,behaviorResult: 具体内容 |
{
type: 'BEHAVIOR_XHR',
info: {
message: '异步请求',
url: 'http://localhost:8001/sockjs-node/info?t=1580906284133',
method: 'GET',
status: 200,
responseSize: null,
statusText: 'OK',
success: true,
duration: 17
},
options: {
token: '9999',
origin: 'http://localhost:9090',
isTest: false,
frequency: 1,
userId: 'wall_KLSkzxldp0fxpyHXOKSuCrMJQoWMoKg2'
},
key: 'NtsGbhvxzDSm1ti2uffSue7u2UIFPVXo',
version: '0.2.2',
createTime: 1580906284151,
currentUrl: 'http%3A%2F%2Flocalhost%3A8001%2F%3Fa%3D1',
project_id: 1,
time: 1581031275,
};
FAQs
## 简介
The npm package wall_sdk receives a total of 23 weekly downloads. As such, wall_sdk popularity was classified as not popular.
We found that wall_sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.