How to get the original native browser objects, if they have changed?

夙愿已清 提交于 2019-12-12 09:12:39

问题


Actually the whole issue. Kind of anti-monkey patching. How to get the original objects (Object, Array, Function, String, etc) and their prototypes, if they have changed \ expanded \ deleted?

The only option that I see now - it is the dynamic creation of the frame - pulling out of his native objects - Remove the frame on the fly. Perhaps the same can be done with the help Web Workers. But they ie> 9, in which there are no classes DOM, and by itself the same way as the dynamic frame.

Example with frame

delete Object.prototype.constructor;
delete Object;

console.log(window.__proto__.__proto__.__proto__.constructor); // undefined
// console.log(Object); // undefined

var frame = document.createElement('frame');
document.all[0].appendChild(frame);

var Object = frames[0].Object;
document.all[0].removeChild(frame);
console.log(Object);

This theoretical question. For example, we are developing an embedded library, and can not know when it will be called, so by the time it is invoked with the native browser objects can be changed. What we need to get the original objects, the initial environment.

Maybe there are other ways to solve?

Thanks in advance.


回答1:


Before posting my answer, I have to tell you that I do not speak english so excuse me for the orthography, and I do not have a solution for your problem but but maybe this helps you.

I was searching for weeks how to get the toString built-in function even if it was redefined and do not found anything (except for creating a new frame, but this solution do not work for me because I am using node js/node webkit).

I start to search inside the window object, for objects that are not configurable so nobody can redefine them and I found this:

Object.getOwnPropertyDescriptor(window, "top");
//Object {value: Window, writable: true, enumerable: true, configurable: false}
Object.getOwnPropertyDescriptor(top.__proto__, "toString");
//Object {value: function, writable: true, enumerable: false, configurable: false}

So if I access top.__proto__.toString always get the real built-in function because is not configurable (and so far I found no way to replace it). This work for me on a webkit client, so I have to keep searching a solution for nodejs.

By the way, I delete the object constructor same as you did and I can not find Object inside the top, but I think it must be stored somewhere. I will keep searching, if I find a solution I will edit this post.

I hope I have helped.



来源:https://stackoverflow.com/questions/25355631/how-to-get-the-original-native-browser-objects-if-they-have-changed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!