里面的欺骗导航器< iframe> [英] Spoof navigator inside <iframe>
问题描述
我希望所有导航器对象实例都是主窗口中的一个,以及在每个iframe中创建的实例都被欺骗。为了让你知道我正在做什么,这不会欺骗每个iframe中的导航器。
Object .defineProperty(HTMLIFrameElement.prototype.contentWindow,navigator,{
可配置:true,
enumerable:true,
值:某个虚假导航器对象
});
也许是因为它实际上是window.HTMLIFrameElement.prototype,那我要去哪里呢?
有什么想法?
如果您不明白这个问题,请询问更多细节。 全局对象(<$ c在$ iframe中的$ c> window )不是从 HTMLIFrameElement
的原型派生的。原型的 contentWindow
属性只是一个访问器,它为您提供了一个跨领域的代理服务器给其他的全局服务器。
用 {all_frames:true,run_at:document-start} $ c $替换每个iframe中运行脚本所需的实际
navigator
c>。
I am writing a browser extension for privacy. One of the things I need to do is spoof the window.navigator object and it's properties which I have managed to do successfully for the main window object. I need to also spoof the window.navigator object for each iframe.contentWindow on the page. I suppose I could use self.frames and then loop through that spoofing each but what about frames that are created after my code runs but that don't exist when my code runs e.g. var myFrame = document.createElement("iframe"); ???
I want all navigator object instances the one in the main window as well as the one created in each iframe to be spoofed. To give you an idea of what I am trying to do, this does not work to spoof the navigator inside each iframe.
Object.defineProperty(HTMLIFrameElement.prototype.contentWindow, "navigator", {
configurable: true,
enumerable: true,
value: "some fake navigator object"
});
Maybe because its actually window.HTMLIFrameElement.prototype and thats where I'm going wrong?
Any ideas? If you don't understand the question please ask for more detail.
The global object (window
) in an iframe is not derived from the HTMLIFrameElement
's prototype. The prototype's contentWindow
property is merely an accessor that gives you a cross-realm proxy to the other global.
To replace the actual navigator
property you need to run a script in each iframe with {all_frames: true, run_at: document-start}
.
这篇关于里面的欺骗导航器< iframe>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!