Spoof navigator inside <iframe>

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 eg 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} .

链接地址: http://www.djcxy.com/p/18346.html

上一篇: 处理MediaFile应用程序中的异常

下一篇: <iframe>内的欺骗导航器