1.js 打印浏览器环境
var eval_env_script = ""; var all_eval_env_script = ""; var base_script = ""; //常用的proxy_array(按照"_"规范填写,后面会进行解析) var proxy_array = ["window", "window_document", "window_location", "window_navigator", "window_history"]; function vmProxy(object) { return new Proxy(object, { set: function (target, property, value) { console.log("set", target, property, value); return Reflect.set(...arguments); }, get: function (target, property, recelver) { console.log("get", target, property, target[property]); if (target[property] == undefined) { //拼接脚本 eval_env_script = target.name.replaceAll("_", ".") + '.' + property; } return target[property]; }, }); } for (var i = 0; i < proxy_array.length; i++) { var proxy_function = proxy_array[i].replaceAll("_", "."); base_script += proxy_function + ' = ' + '{};\r\n'; eval(proxy_function + ' = ' + 'vmProxy(function ' + proxy_array[i] + '(){})'); } function get_env_script(source_js_code, count) { //最多循环conut次,防止一直无法得到环境 for (var i = 0; i < count; i++) { try { eval(source_js_code);//需要补环境的js break;//成功后退出循环 } catch (err) { if (err.message.indexOf('Cannot read') != -1) { eval_env_script += ' = "";'; } else if (err.message.indexOf('is not a function') != -1) { eval_env_script += ' = function() {return {};}'; } eval(eval_env_script); all_eval_env_script += "\r\n" + eval_env_script; } } all_eval_env_script = base_script + all_eval_env_script; console.log("result: \r\n" + all_eval_env_script); return all_eval_env_script; } get_env_script(`window.name="name"`, 10)
2.js 打印浏览器环境
(function() { // hook随机数 'use strict'; Date.now = function now() { return 1699237962590 }; Date.parse = function () { return 1699237962590 }; Date.prototype.valueOf = function () { return 1699237962590 }; Date.prototype.getTime = function () { return 1699237962590 }; Date.prototype.toString = function () { return 1699237962590 }; Math.random = function random() { return 0.08636862211354912 }; })(); window = new Proxy(window, { // 代理window 方便查看日志 set(target, property, value, receiver) { console.log("设置属性set window", property, typeof value); return Reflect.set(...arguments); }, get(target, property, receiver) { console.log("获取属性get window", property, typeof target[property]); return target[property] } }); function proxy (proxy_array) { // 异常报错前断住 for (let i=0; i<proxy_array.length; i++){ eval(proxy_array[i] + `= new Proxy(` + proxy_array[i] + `, { get(target, key) { if(key == '你需要debugger的属性'){ debugger; } console.log('----------------------') // console.log( '【` + proxy_array[i]+ `】取属性 ' + key + ', 详细位置debugger查看'); // target[key] 为某些对象时, 拼接字符串会异常,如 window['document'] console.log( '【` + proxy_array[i]+ `】取属性 ' + key + ' 值: ' + target[key] + ', 详细位置debugger查看'); console.log('----------------------') return target[key]; } });`) } }; // 数组中放入需要代理的对象 var proxy_array = ['document', 'navigator','location']; proxy(proxy_array);;
标签:function,浏览器,env,script,打印,环境,eval,return,property From: https://www.cnblogs.com/yoyo1216/p/17893676.html