里面的欺骗导航器< iframe> [英] Spoof navigator inside <iframe>

查看:222
本文介绍了里面的欺骗导航器< iframe>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个隐私浏览器扩展。我需要做的一件事就是欺骗window.navigator对象,这是我为主窗口对象成功完成的属性。我还需要欺骗页面上的每个iframe.contentWindow的window.navigator对象。我想我可以使用self.frames,然后通过欺骗每个循环,但是我的代码运行后创建的框架,但是我的代码运行时不存在var myFrame = document.createElement(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} 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}.

这篇关于里面的欺骗导航器&lt; iframe&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆