Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
@ued2345/octopus-util
Advanced tools
├── build
│ ├── build.js // 执行打包 npm run build
│ └── webpack.conf.js // webpack配置文件
├── dist
│ ├── octopus-util.min.js // 打包后的文件,也是被其它项目引入的文件
├── src
│ ├── device
│ │ │── getBrowser.ts // 获取操作系统类型
│ │ └── gettInApp.ts // 判断是否在APP内
│ ├── cookie
│ │ │── getCookie.ts // 获取cookie
│ │ │── setCookie.ts // 设置cookie
│ │ └── delCookie.ts // 删除cookie
│ ├── jsbrige
│ │ │── init // 二级目录
│ │ │ │── bridge.ts // 定义类型
│ │ │ └── brigeInit.ts // 创建bridge对象
│ │ └── jsBrige.ts // export jsbridge方法
│ ├── vue-plugin
│ │ │── directives // vue全局指令
│ │ │ └── bang // 埋点指令
│ │ └── vuePlugin.ts // export vuePlugin
│ └── index.ts // webpack打包入口文件
├── .babelrc // babel配置文件
├── tsconfig.config.js // ts配置文件
├── README.md // 项目说明文档
第一步:npm run build
第二步:npm发包
octopus = {
// 获取操作系统类型
getBrowser: () => {
android: boolean,
gecko: boolean,
iPad: boolean,
iPad: boolean,
iPhone: boolean,
ios: boolean,
mobile: boolean,
presto: boolean,
qq: boolean,
trident: boolean,
webApp: boolean,
webKit: boolean,
weixin: boolean,
},
// 通过userAgent 判断是否在APP内
getInApp: (uName) => {return boolean},
// JsBridge 与原生通信
JsBridge: {
// js调用webview事件
callHandle: ({method, params}, callback) => {},
// webView调用JS事件
registerHandle: (method, callback) => {},
},
// cookie 操作
setCookie: (name, value, days) => {},
getCookie: (name) => {},
delCookie: (name) => {}
}
npm install --save-dev @ued2345/octopus-util
<script src="octopus-util.min.js"></script>
<script>
var browser = window.OcUtil.getBrowser()
</script>
import OcUtil from '@ued2345/octopus-util'
const browser = OcUtil.getBrowser()
// 或单独引用方法
import {getBrowser} from '@ued2345/octopus-util'
优化大部分在项目中业务代码中混入埋点代码的情况
优化大部分曝光、挂载、点击的埋点的上报的书写方式,使用vue指令的方式
// main.js 或单页应用入口js
import OcUtil from '@ued2345/octopus-util'
// 模拟上报函数(参数同vue自定义指令)
const bang = (el, binding) => {console.log(`触发上报,类型:${binding.arg},值: ${binding.value}`)}
Vue.use(OcUtil, {
bang: {
// 自定义配置
cb: bang
}
})
// test.vue
<div v-bang:exposure="`我曝光啦`"></div> //曝光后输出: "触发上报,类型:exposure,值: 我曝光啦"
低版本兼容 因为低版本机型不支持intersectionObserver需要安装相应polyfill,具体步骤如下:
import 'intersection-observer'
支持配置
参数 | 说明 | 类型 | 是否必须 | 默认 |
---|---|---|---|---|
cb | 触发上报后的回调函数 | 同vue自定义指令钩子函数,(el: HTMLElement, binding: DirectiveBinding, vnode: vnode, oldVnode: vnode) => void 详见官网 | 是 | 无 |
clickThrottleInterval | 点击事件上报节流的间隙时间 | number | 否 | 2000 |
exposureMulti | 元素未销毁时是否可以多次发送曝光统计事件 | boolean | false | |
imgErrExposure | 图片加载出错的时候是否算曝光成功(曝光事件绑定在img元素上时) | boolean | false |
<div v-if="show" v-bang:mounted="`显示1`" key="显示1">显示1</div>
<div v-else v-bang:mounted="`显示2`" key="显示2">显示2</div>
FAQs
ued2345 utils
The npm package @ued2345/octopus-util receives a total of 4 weekly downloads. As such, @ued2345/octopus-util popularity was classified as not popular.
We found that @ued2345/octopus-util demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.