gpt4 book ai didi

javascript - <iframe> 中的欺骗导航器

转载 作者:行者123 更新时间:2023-11-30 15:06:33 24 4
gpt4 key购买 nike

我正在为隐私编写一个浏览器扩展。我需要做的一件事是欺骗 window.navigator 对象及其属性,我已经成功地为主窗口对象完成了这些属性。我还需要为页面上的每个 iframe.contentWindow 欺骗 window.navigator 对象。我想我可以使用 self.frames 然后循环遍历每个欺骗,但是在我的代码运行后创建但在我的代码运行时不存在的帧呢? var myFrame = document.createElement("iframe"); ???

我希望欺骗所有导航器对象实例,包括主窗口中的导航器对象实例以及在每个 iframe 中创建的导航器对象实例。为了让您了解我正在尝试做什么,这无法欺骗每个 iframe 内的导航器。

Object.defineProperty(HTMLIFrameElement.prototype.contentWindow, "navigator", {
configurable: true,
enumerable: true,
value: "some fake navigator object"
});

也许是因为它实际上是 window.HTMLFrameElement.prototype 而这就是我出错的地方?

有什么想法吗?如果您不明白这个问题,请询问更多细节。

最佳答案

iframe 中的全局对象 (window) 不是从 HTMLFrameElement 的原型(prototype)派生的。原型(prototype)的 contentWindow 属性只是一个访问器,它为您提供另一个全局的跨领域代理。

要替换实际的 navigator 属性,您需要使用 {all_frames: true, run_at: document-start} 在每个 iframe 中运行脚本。

关于javascript - &lt;iframe&gt; 中的欺骗导航器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45656585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com