简体   繁体   English

Firefox在此简单枚举上抛出安全错误1000

[英]Firefox throws security error 1000 on this simple enumeration

I'll make it short: 我会简短地说:

I want to enum all available functions and objects inside of window object for creating some kind of object reflection code. 我想枚举window对象内部的所有可用函数和对象,以创建某种对象反射代码。
it runs just fine in every browser but in Firefox. 在Firefox中,它在所有浏览器中都能正常运行。 here is my pseudo loop code: 这是我的伪循环代码:

var all_names=[];
for (var i in window)
{
    //if it's NOT an object
    all_name.push(i.toString());
    //if it's an object        
    enum up to 3 more levels in child objects.
}

And I don't want to use available APIs in Firefox such as getOwnPropertyNames . 而且我不想在Firefox中使用可用的API,例如getOwnPropertyNames
So, what should I do? 所以我该怎么做? is there any better solution for enumeration in Javascript (cross-browser of course) 有没有更好的Java枚举解决方案(当然是跨浏览器)


Here is some more technical info: 这里是一些更多的技术信息:

Exact Firefox error: 确切的Firefox错误:

[20:48:04.539] uncaught exception: [Exception... "Security error" code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" location: "http://localhost/test/common.js Line: 53"]

Exact enum loop code: 确切的枚举循环代码:

 function reflectAsString() { try{ var m1 = ""; var m2 = ""; var m3 = ""; for (var i in window) { if(window[i] && window[i]!= null && window[i] != "globalStorage") { m1 += i; first_instance = window[i]; if(typeof first_instance == "object") { for(var j in first_instance) { if(first_instance[j] && first_instance[j]!= null) { m2 += j; second_instance = first_instance[j]; if(typeof second_instance == "object") { for (var k in second_instance) { if(second_instance[k] && second_instance[k]!= null) { m3 += k; } } } } } } } } return hex_md5(hex_md5(m1)+hex_md5(m2)+hex_md5(m3)); } catch(e) { try { var strToHash = Object.getOwnPropertyNames(window).filter(function(property) { return typeof window[property] == 'function'; }); return hex_md5(strToHash.toString()); } catch(e2) { return "undef"; } } } 

I have done something similar by opening an iframe on the page I am interested in, and comparing the globals in the iframe's window with those in the parent window. 通过在我感兴趣的页面上打开一个iframe,然后将iframe窗口中的全局变量与父窗口中的全局变量进行比较,我做了类似的事情。 The try block will return the property name with an error flag, if there are any errors. 如果有任何错误,try块将返回带有错误标志的属性名称。

HTML for iframe src: 用于iframe src的HTML:

<html lang= "en">
<head>
<meta charset= "utf-8">
<title>Get Globals</title>
<style>
p{border:none;font-size:1.25em;font-weight:600;}
h2{color:navy;border-top:3px ridge navy;margin:1ex 0;}
span{margin:0 1em;}
</style>
<script>
navigator.sayswho= (function(){
    var N= navigator.appName, ua= navigator.userAgent, tem,
    ie= navigator.IEmod,
    M= ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*([\d\.]+)/i);
    if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1];
    M= M? [M[1], M[2]]:[N, navigator.appVersion, '-?'];
    if(ie && ie!= M[1]) M[2]= 'ie mode:'+navigator.IEmod;
    return M.join(' ');
})();
window.onload= function(){
    if(this!= top){
        var G={
            getInterface:1, InstallTrigger:1
        },
        B= [], C= [], k= ['HTML elements:'], d= navigator.sayswho || '',
        t= document.getElementsByTagName('p');
        for(var p in this) G[p]= 1;
        for(var key in top){
            try{
                if(!(key in G)){
                    if(top[key].nodeType== 1) k.push(key);
                    else B.push(key);
                }
                else C.push(key);
            }
            catch(er){
                B.push('error with '+key);
            }
        }
        if(k.length>1) B.push(k.join(' '));
        if(d) document.getElementsByTagName('span')[0].innerHTML+= d;
        t[0].innerHTML= B.join('<br>');
        t[1].innerHTML= C.sort().join(', ');
    }
}
</script>
</head>
<body>
<h1>Globals<span>in</span></h1>
<h2>New globals defined in the top window</h2>
<p></p>
<h2>Common window properties</h2>
<p></p>
</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM