神秘的“类型错误:非本地范围对象”在Firebug [英] Mysterious "Type Error: non-native scope object" in Firebug

查看:314
本文介绍了神秘的“类型错误:非本地范围对象”在Firebug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面的HTML:

 <!DOCTYPE html> 
< html>
< body>
测试页

<! - Zopim Live Chat Script开始 - >
< script type =text / javascript>
window $ zopim ||(function(d,s){var z = $ zopim = function(c){z ._ push(c)},$ = zs =
d.createElement (s),e = d.getElementsByTagName(s)[0]; z.set = function(o){z.set。
_.push(o)}; z ._ = []; z。 set ._ = []; $。async =!0; $。setAttribute('charset','utf-8');
$ .src ='// cdn.zopim.com/?pTR0FiicfJ4aMcmuHI9HfVAB4uzKeFIT'; zt = + new Date; $。
type ='text / javascript'; e.parentNode.insertBefore($,e)})(document,'script');
< / script>
<! - Zopim Live Chat Script结束 - >

< script type =text / javascriptasync =>
window.addEventListener('load',function(){
var b = document.getElementsByTagName(body)[0];
var o = document.createElement(object) ;
o.setAttribute(type,application / x-shockwave-flash);
var t = b.appendChild(o);
});
< / script>
< / body>
< / html>

jsFiddle here: http://jsfiddle.net/V9jtD/



它包含Zopim小部件代码,另一个异步脚本,只是添加一个对象标签到DOM。让上述文件由web服务器(您可以使用jsFiddle: http://fiddle.jshell。净/ V9jtD /显示/ )。打开它在MacOSX Firefox 15 + Firebug激活。



您会看到下面的错误重复多次:

 

但是,在以下情况下,Zopim会加载:


  1. 注释掉var t = b.appendChild(o); (即,不要将object标签附加到DOM,或者您可以完全移除第二个脚本标签)。
  2. 停用Firebug。

我基本上想知道是谁在引发这个错误,所以我可以调试它。

<它是萤火虫,因为停用它Zopim工作正常?但是,在启用Firebug的情况下删除第二个脚本标记不会导致错误。

是否是第二个脚本标记,因为删除它Zopim的作品精细?但是,然后停用Firebug,Zopim甚至可以使用第二个脚本标记。

请注意,第二个脚本标记中的内容是swfobject.js中的函数testPlayerVersion()的一部分。我试图将Zopim添加到已有swfobject的页面中时遇到了此错误。

如果小提琴不是从Zopim加载JS的缩小版,但是这个违规的代码(大致美化的)是:

  try {
(0)()
} catch(v){
s = v.arguments?
'chrome':v.stack?
'firefox':window.opera&& !(v中的stacktrace)?
'opera':'other'
}

这看起来像一个哈克浏览器的检测方式。我不确定为什么它会导致Firebug保释,如果它是可重现的,那么可能值得提出一个问题。


Consider the following HTML:

<!DOCTYPE html>
<html>
<body>
Test page

<!--Start of Zopim Live Chat Script-->
<script type="text/javascript">
window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s=
d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.
_.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute('charset','utf-8');
$.src='//cdn.zopim.com/?pTR0FiicfJ4aMcmuHI9HfVAB4uzKeFIT';z.t=+new Date;$.
type='text/javascript';e.parentNode.insertBefore($,e)})(document,'script');
</script>
<!--End of Zopim Live Chat Script-->

<script type="text/javascript" async="">
window.addEventListener('load', function() {
    var b = document.getElementsByTagName("body")[0];
    var o = document.createElement("object");
    o.setAttribute("type", "application/x-shockwave-flash");
    var t = b.appendChild(o);
});
</script>
</body>
</html>

jsFiddle here: http://jsfiddle.net/V9jtD/

It contains Zopim widget code, another async script that just adds an "object" tag to DOM. Let the above file be served by a webserver (you can use the jsFiddle: http://fiddle.jshell.net/V9jtD/show/). Open it in MacOSX Firefox 15+ with Firebug activated.

You will see the following error repeated many times:

TypeError: non-native scope object

If the errors donot show up, just refresh the page. And mainly Zopim fails to show up (sometimes appears with incomplete functionality). I could not reproduce this in Firefox/Ubuntu. (It might be reproducible in Firefox/Windows I could not check).

However, in the following cases Zopim loads fine:

  1. Comment out "var t = b.appendChild(o);" (ie. dont append the "object" tag to DOM, or you can just remove second script tag entirely).
  2. Deactivate Firebug.

I essentially want to understand who is causing the error so I can debug it.

Is it Firebug, because deactivating it Zopim works fine? But then removing the second script tag with Firebug enabled does not cause the error.

Is it the second script tag, because removing it Zopim works fine? But then deactivate Firebug and Zopim works fine even with second script tag.

Or is it Zopim itself?

Note that the content in the second script tag is part of function testPlayerVersion() in swfobject.js. I have hit this error when I am trying to add Zopim to a page that already has swfobject.

解决方案

It would probably be easier to work out if the fiddle wasn't loading minified JS from Zopim, but the offending line (roughly beautified) is:

try {
    (0)()
} catch (v) {
    s = v.arguments ?
        'chrome' : v.stack ?
        'firefox' : window.opera && !('stacktrace' in v) ?
        'opera' : 'other'
}

Which looks like a hacky way of detecting the browser. I'm not sure why it's causing Firebug to bail, it might be worth raising an issue with them if it's reproducible.

这篇关于神秘的“类型错误:非本地范围对象”在Firebug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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