在Javascript中记录方法调用和属性访问
我想知道是否有任何方法可以在Javascript中记录所有方法调用(带参数)和属性访问。 例如: 1-我希望在在Javascript中记录方法调用和属性访问,javascript,dom,hook,Javascript,Dom,Hook,我想知道是否有任何方法可以在Javascript中记录所有方法调用(带参数)和属性访问。 例如: 1-我希望在document.createElement(“canvas”)创建画布时得到通知 2-当脚本试图访问navigator.plugins或window.screen时,需要通知我 提前感谢。您可以向函数添加挂钩,例如: let调用=(函数(){ let calls=0; 让fun=document.createElement; document.createElement=函数(){
document.createElement(“canvas”)创建画布时得到通知代码>
2-当脚本试图访问navigator.plugins
或window.screen
时,需要通知我
提前感谢。您可以向函数添加挂钩,例如:
let调用=(函数(){
let calls=0;
让fun=document.createElement;
document.createElement=函数(){
调用++;
返回fun.apply(文档、参数);
}
return()=>调用;
})();
让canvas=document.createElement(“canvas”);
document.body.appendChild(画布);
var ctx=canvas.getContext('2d');
ctx.fillStyle='rgb(200,0,0)';
ctx.fillRect(10,10,50,50);
log(“调用document.createElement:,calls())代码>您可以向函数添加钩子,例如:
let调用=(函数(){
let calls=0;
让fun=document.createElement;
document.createElement=函数(){
调用++;
返回fun.apply(文档、参数);
}
return()=>调用;
})();
让canvas=document.createElement(“canvas”);
document.body.appendChild(画布);
var ctx=canvas.getContext('2d');
ctx.fillStyle='rgb(200,0,0)';
ctx.fillRect(10,10,50,50);
log(“调用document.createElement:,calls())
亲爱的Denys,我想知道如何专门为windows.navigator.plugins定义代理,windows.navigator太笼统了,例如,我想为navigator.useragent定义代理,但我收到无效JavaScriptDenys的错误亲爱的Denys,我想知道如何专门为windows.navigator.plugins定义代理,windows.navigator太通用了,例如,我想为navigator.useragent定义一个代理,但我得到了无效Javascript的错误