{"id":20675315,"url":"https://github.com/jsrei/javascript-window-listener-library","last_synced_at":"2025-04-19T20:34:17.579Z","repository":{"id":51205433,"uuid":"517929014","full_name":"JSREI/javascript-window-listener-library","owner":"JSREI","description":"javascript逆向开发基础组件，监听window的变化","archived":false,"fork":false,"pushed_at":"2024-02-11T17:41:50.000Z","size":18,"stargazers_count":15,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T13:04:56.577Z","etag":null,"topics":["crawler","js-library","js-reverse","reverse-engineering","web-security-research"],"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/JSREI.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":"2022-07-26T05:44:14.000Z","updated_at":"2025-02-22T06:27:51.000Z","dependencies_parsed_at":"2023-01-20T12:47:16.289Z","dependency_job_id":null,"html_url":"https://github.com/JSREI/javascript-window-listener-library","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JSREI%2Fjavascript-window-listener-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JSREI%2Fjavascript-window-listener-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JSREI%2Fjavascript-window-listener-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JSREI%2Fjavascript-window-listener-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JSREI","download_url":"https://codeload.github.com/JSREI/javascript-window-listener-library/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249794976,"owners_count":21326776,"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":["crawler","js-library","js-reverse","reverse-engineering","web-security-research"],"created_at":"2024-11-16T21:09:08.610Z","updated_at":"2025-04-19T20:34:17.554Z","avatar_url":"https://github.com/JSREI.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# javascript逆向开发基础组件： window监听器\n\n# 一、 简介\n\n用于监听window的变化，目前只有新增全局变量监控，最初是为了用在javascript hook库中实现对window变量的proxy功能。\n\n# 二、Example\n\n```js\n(async () =\u003e {\n\n    const monitor = new WindowMonitor();\n    // 在window新增变量时会触发此处传入的Listener函数，Listener函数可以有多个 \n    await monitor.addWindowListener(key =\u003e {\n        console.log(new Date(), key);\n    });\n    // 启动监控器，其实就是个while循环不断的检查window上是否有新增变量 \n    await monitor.startWindowMonitor();\n\n})();\n\nconst chars = \"ABCDEFGHJKMNPQRSTWXYZ\"\n\nfunction randomString(length) {\n    length = length || 100;\n    const charArray = [];\n    for (let i = 0; i \u003c length; i++) {\n        charArray.push(chars.charAt(Math.floor(Math.random() * chars.length)));\n    }\n    return charArray.join(\"\");\n}\n\nfunction genGlobalVars() {\n    window[randomString(40)] = randomString(6);\n    setTimeout(genGlobalVars, Math.random() * 10)\n}\n\nsetTimeout(() =\u003e {\n    genGlobalVars();\n}, Math.random() * 10)\n\n```\n\n# 三、原理\n\n其实原理简单粗暴，就是每隔一段时间遍历window对其所有属性做一个快照，然后前后快照做diff，就能够找出来新增的变量或者删除的变量，对于第一个快照会认为是初始化，这样就能够把默认的属性给识别出来不触发新增事件。\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsrei%2Fjavascript-window-listener-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsrei%2Fjavascript-window-listener-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsrei%2Fjavascript-window-listener-library/lists"}