我有这段代码来记录对一堆window.navigator属性的调用:
var navigatorProperties = [ "appCodeName", "appMinorVersion", "appName", "appVersion", "cookieEnabled", "cpuClass", "onLine", "opsProfile", "platform", "product", "systemLanguage", "userAgent", "userLanguage", "userProfile" ];
var contentStorage = {};
navigatorProperties.forEach(
function(property) {
contentStorage["window.navigator." + property] = window.navigator[property];
Object.defineProperty(window.navigator, property, {
configurable: true,
get: function() { logValue("window.navigator." + property, contentStorage["window.navigator." + property], "get"); return contentStorage["window.navigator." + property] },
set: function(value) { logValue("window.navigator." + property, contentStorage["window.navigator." + property], "set"); contentStorage["window.navigator." + property] = value; }
});
});
当此代码存在于常规网页中时,对定义和监视属性的任何调用,如console.log('local page:'+ window.navigator.product);工作正常,也就是说,我得到logValue执行输出。但是,我希望此代码存在于插件SDK内置的扩展内容注入脚本中,我通过页面mod API注入。当我这样做,并转到修改或访问我看到的属性的页面时,logValue永远不会被触发。我试过用unsafeWindow替换窗口,但也没有运气。任何人都有任何关于为什么这个代码通过插件注入时无效的指针?