【发布时间】:2015-08-07 07:11:00
【问题描述】:
我曾经使用alert() 进行调试,当我在 JavaScript/jQuery 中编写一些代码行时(我知道,这是不好的风格)。我现在在 Google Chrome 中看到一个奇怪的行为。
HTML
<html>
<head>
<script src="my_script.js"></script>
</head>
<body>
<p>Test</p>
</body>
</html>
my_script.js
这真的很简单。
alert("hello world");
错误
当我加载页面时它通常可以正常工作,但是当我重新加载页面时有时谷歌浏览器会出现以下错误:
Uncaught TypeError: Cannot read property 'impl' of undefined extensions::messaging:184
经过多次测试,我发现
-
alert()窗口按预期显示 - 错误并非每次都会发生,但有时会发生
- 错误发生(发生时)在关闭
alert()窗口后 - 如果我等待关闭
alert()窗口,或在两次重新加载之间,似乎不会发生错误
错误信息指向这个代码-sn-p:
// In case the extension never invokes the responseCallback, and also
// doesn't keep a reference to it, we need to clean up the port. Do
// so by attaching to the garbage collection of the responseCallback
// using some native hackery.
messagingNatives.BindToGC(responseCallback, function() {
if (port) {
privates(port).impl.destroy_();
port = null;
}
});
但我什至无法弄清楚哪个文件受到影响以及它被放置在哪个文件夹中。
Google 刚刚发现了另一个明显相同错误的描述: https://teamtreehouse.com/forum/anyone-else-getting-error-cannot-read-property-impl-of-undefined
这个页面的作者假设这个错误只是有时发生的事实,指向一个异步进程的问题,有时没有完成重新加载页面。
我通过改用console.log() 解决了我的调试任务。但我很感兴趣究竟发生了什么错误,以及如何通过使用alert() 函数来避免它返回到我糟糕的调试方式。
【问题讨论】:
-
听起来像一个 chrome 错误。举报。