Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Javascript中记录方法调用和属性访问_Javascript_Dom_Hook - Fatal编程技术网

在Javascript中记录方法调用和属性访问

在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=函数(){

我想知道是否有任何方法可以在Javascript中记录所有方法调用(带参数)和属性访问。 例如: 1-我希望在
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的错误