{"id":13671497,"url":"https://github.com/BetterJS/badjs-report","last_synced_at":"2025-04-27T18:31:21.086Z","repository":{"id":23262314,"uuid":"26620645","full_name":"BetterJS/badjs-report","owner":"BetterJS","description":"monitor error and report ","archived":false,"fork":false,"pushed_at":"2018-11-30T07:17:06.000Z","size":575,"stargazers_count":1138,"open_issues_count":19,"forks_count":193,"subscribers_count":46,"default_branch":"master","last_synced_at":"2024-10-29T09:15:38.877Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BetterJS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-14T03:28:59.000Z","updated_at":"2024-09-03T04:27:27.000Z","dependencies_parsed_at":"2022-07-13T15:59:19.815Z","dependency_job_id":null,"html_url":"https://github.com/BetterJS/badjs-report","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetterJS%2Fbadjs-report","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetterJS%2Fbadjs-report/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetterJS%2Fbadjs-report/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetterJS%2Fbadjs-report/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BetterJS","download_url":"https://codeload.github.com/BetterJS/badjs-report/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251187151,"owners_count":21549595,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T09:01:11.125Z","updated_at":"2025-04-27T18:31:20.789Z","avatar_url":"https://github.com/BetterJS.png","language":"JavaScript","readme":"badjs-report -- 前端日志上报与JS异常监控\r\n---\r\n\r\n[![Build Status](https://travis-ci.org/BetterJS/badjs-report.svg?branch=master)](https://travis-ci.org/BetterJS/badjs-report)\r\n[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/BetterJS?utm_source=share-link\u0026utm_medium=link\u0026utm_campaign=share-link)\r\n## Author\r\n[caihuiji](https://github.com/caihuiji) [yorts52](https://github.com/yorts52)\r\n\r\n## Install\r\n\r\n```shell\r\n$ npm install badjs-report\r\n```\r\n```shell\r\n$ bower install https://github.com/BetterJS/badjs-report.git\r\n```\r\n```shell\r\n$ lego install badjs-report --save\r\n```\r\n\r\n## Getting Started\r\n\u003e badjs-report 必须在所有类库之前加载并初始化。\r\n\u003e 但是要在 jquery、seajs、requrejs等类库后调用spyAll()。\r\n\r\n##### 初始化\r\n```javascript\r\nBJ_REPORT.init({\r\n  id: 1                                 // 不指定 id 将不上报\r\n});\r\n```\r\n##### 配置说明\r\n```javascript\r\nBJ_REPORT.init({\r\n  id: 1,                                // 上报 id, 不指定 id 将不上报\r\n  uin: 123,                             // 指定用户 id, (默认已经读取 qq uin)\r\n  delay: 1000,                          // 延迟多少毫秒，合并缓冲区中的上报（默认）\r\n  url: \"//badjs2.qq.com/badjs\",         // 指定上报地址\r\n  ignore: [/Script error/i],            // 忽略某个错误\r\n  random: 1,                            // 抽样上报，1~0 之间数值，1为100%上报（默认 1）\r\n  repeat: 5,                            // 重复上报次数(对于同一个错误超过多少次不上报)\r\n                                        // 避免出现单个用户同一错误上报过多的情况\r\n  onReport: function(id, errObj){},     // 当上报的时候回调。 id: 上报的 id, errObj: 错误的对象\r\n  submit: null,                         // 覆盖原来的上报方式，可以自行修改为 post 上报等\r\n  ext: {},                              // 扩展属性，后端做扩展处理属性。例如：存在 msid 就会分发到 monitor,\r\n  offlineLog : false,                   // 是否启离线日志 [默认 false]\r\n  offlineLogExp : 5,                    // 离线有效时间，默认最近5天\r\n});\r\n```\r\nBJ_Report 是重写了 window.onerror 进行上报的，无需编写任何捕获错误的代码\r\n\r\n#####  手动上报\r\n```javascript\r\nBJ_REPORT.report(\"error msg\");\r\n\r\nBJ_REPORT.report({\r\n  msg: \"xx load error\",                 // 错误信息\r\n  target: \"xxx.js\",                     // 错误的来源js\r\n  rowNum: 100,                          // 错误的行数\r\n  colNum: 100,                          // 错误的列数\r\n});\r\n\r\ntry{\r\n    // something throw error ...\r\n}catch(error){\r\n    BJ_REPORT.report(e);\r\n}\r\n```\r\n\r\n#####  延迟上报\r\n\r\n```javascript\r\nBJ_REPORT.push(\"error msg\");\r\n\r\nBJ_REPORT.push({\r\n  msg: \"xx load error\",                 // 错误信息\r\n  target: \"xxx.js\",                     // 错误的来源js\r\n  rowNum: 100,                          // 错误的行数\r\n  colNum: 100,                          // 错误的列数\r\n});\r\n\r\nBJ_REPORT.report();\r\n\r\n```\r\n\r\n#####  上报离线日志  \r\n\r\n```javascript\r\nBJ_REPORT.reportOfflineLog();\r\n```\r\n\r\n\u003e 什么是离线日志？ [#25](https://github.com/BetterJS/badjs-report/issues/25)\r\n\r\n#####  用法\r\n```javascript\r\n//初始化\r\nBJ_REPORT.init({id: 1})\r\n\r\n//主动上报错误日志\r\nBJ_REPORT.report(\"error msg 2\");\r\n\r\n//info上报，用于记录操作日志\r\nBJ_REPORT.info(\"info\");\r\n\r\n//可以结合实时上报，跟踪问题; 不存入存储\r\nBJ_REPORT.debug(\"debug\");\r\n\r\n//记录离线日志  \r\nBJ_REPORT.offlineLog(\"offlineLog\");\r\n```\r\n\u003cbr/\u003e\r\n\r\n### 高级用法\r\n\u003escript error  的错误，怎么解决？  [#3](https://github.com/BetterJS/badjs-report/issues/3)\r\n\r\n由于 BJ_Report 只是重写了onerror 方法而已，而且浏览器的跨域问题不能获得外链 javascript 的错误，所以使用tryJs  进行包裹。\r\n#### 包裹jquery\r\n```javascript\r\nBJ_REPORT.tryJs().spyJquery();\r\n```\r\n包裹 jquery 的 event.add , event.remove , event.ajax 这几个异步方法。\r\n\u003cbr/\u003e\r\n\u003cbr/\u003e\r\n#### 包裹 define , require\r\n```javascript\r\nBJ_REPORT.tryJs().spyModules();\r\n```\r\n包裹 模块化框架 的 define , require 方法\r\n\u003cbr/\u003e\r\n\u003cbr/\u003e\r\n#### 包裹  js 默认的方法\r\n```javascript\r\nBJ_REPORT.tryJs().spySystem();\r\n```\r\n包裹 js 的 setTimeout , setInterval 方法\r\n\u003cbr/\u003e\r\n\u003cbr/\u003e\r\n#### 包裹 自定义的方法\r\n```javascript\r\nvar customFunction = function (){};\r\ncustomFunction  = BJ_REPORT.tryJs().spyCustom(customFunction );\r\n\r\n// 只会包裹 customOne  , customTwo\r\nvar customObject = { customOne : function (){} , customTwo : function (){} , customVar : 1}\r\nBJ_REPORT.tryJs().spyCustom(customObject );\r\n```\r\n包裹 自定义的方法或则对象\r\n\u003cbr/\u003e\r\n\u003cbr/\u003e\r\n#### 运行所有默认的包裹\r\n```javascript\r\n//自动运行 SpyJquery , SpyModule , SpySystem\r\nBJ_REPORT.tryJs().spyAll();\r\n```\r\n\r\n## update log\r\n##### v1.3.3\r\n1. BUGFIX\r\n\r\n##### v1.3.1\r\n1. 支持离线日志\r\n2. 支持自动上报离线日志\r\n\r\n##### v1.2.3\r\n1. BUGFIX\r\n\r\n##### v1.2.1\r\n1. 增加去除重复参数\r\n2. 修复了 webpack 引入问题\r\n3. BUGFIX\r\n\r\n##### v1.1.8\r\n1. 项目重命名后更新项目路径(注: 之前名字为`report`)\r\n\r\n##### v1.1.7\r\n1. 合并上报的问题\r\n2. 增加sea.use try-catch 处理\r\n\r\n##### v1.1.6\r\n1. add BJ_ERROR hash\r\n\r\n##### v1.1.5\r\n1. bugfix\r\n\r\n##### v1.1.4\r\n1. 增加info 和 debug 接口\r\n2. report 增加对 error 对象处理\r\n3. 处理 [Object event] 问题\r\n\r\n##### v1.1.3\r\n1. bugfix\r\n\r\n##### v1.1.2\r\n1. 增加抽样参数 random\r\n\r\n##### v1.1.1\r\n1. seajs 兼容的BUG修复\r\n2. 增加 ext 属性，用户可以自己定义里面的值上报\r\n\r\n##### v1.1.0\r\n1. 增加对seajs 模块化的包裹\r\n2. 增加对IE下面的错误的上报\r\n\r\n##### v1.0.5\r\n1. 修复异步环境下抛给浏览器的BUG也会上报，\r\n2. 修复ignore 数组判断的迭代的问题\r\n\r\n##### v1.0.4\r\n1. 修复 spy 插件增加在 异步环境中，抛出异常捕获后，再抛给浏览器\r\n2. 修复 增加在异步环境中，抛出异常，捕获后，将错误信息输出\r\n3. 增加onReport 回调\r\n\r\n##### v1.0.3\r\n1. 修复说明文档\r\n\r\n##### v1.0.2\r\n1. 修复 uin 的正则\r\n\r\n##### v1.0.1\r\n1. 增加 spy 插件\r\n\r\n##### v1.0.0\r\n1. 功能上线\r\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBetterJS%2Fbadjs-report","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBetterJS%2Fbadjs-report","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBetterJS%2Fbadjs-report/lists"}