简体   繁体   English

alert()有时会导致Chrome出错

[英]alert() sometimes causes an error in Chrome

I used to use alert() for debugging, when I code some lines in JavaScript/jQuery (I know, it is bad style). 我曾经使用alert()进行调试,当我在JavaScript / jQuery中编写一些代码行时(我知道,它是糟糕的样式)。 I now see a strange behaviour in Google Chrome. 我现在在Google Chrome中看到一种奇怪的行为。

HTML HTML

    <html>
    <head>
        <script src="my_script.js"></script>
    </head>
    <body>
    <p>Test</p>
    </body>
    </html>

my_script.js my_script.js

This is really simple. 这很简单。

    alert("hello world");

Error 错误

When I load the page it normally works fine, but when I reload the page sometimes the following error occurs in Google Chrome: 当我加载页面时,它通常可以正常工作,但是当我重新加载页面时, 有时 Google Chrome中会出现以下错误:

Uncaught TypeError: Cannot read property 'impl' of undefined extensions::messaging:184 未捕获的TypeError:无法读取未定义扩展的属性'impl':: messaging:184

By testing it several times I found that 通过多次测试,我发现了这一点

  • the alert() window appears as expected alert()窗口按预期显示
  • the error occurs not every time but sometimes 错误不是每次都发生,而是偶尔发生
  • the error occurs (when it occurs) after closing the alert() window 关闭alert()窗口发生错误(发生时)
  • the error seems not to occur if I wait to close the alert() window, or between two reloads 如果我等待关闭alert()窗口或两次重新加载之间似乎不会发生错误

The error message points to this code-snippet: 错误消息指向此代码段:

  // 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;
    }
  });

But I even couldn't figure out which file is exactly affected and in which folder it is placed. 但我甚至无法确定哪个文件受到了严重影响,以及它放在哪个文件夹中。

Google just found one another description of obviously the same error: https://teamtreehouse.com/forum/anyone-else-getting-error-cannot-read-property-impl-of-undefined 谷歌刚刚发现另一个明显相同错误的描述: https//teamtreehouse.com/forum/anyone-else-getting-error-cannot-read-property-impl-of-undefined

The author of this page supposes that the fact, the error occurs only sometimes, points to a problem with an asynchronous process, which is not finished sometimes one reloads the page. 本页的作者假设,事实上,错误只是偶尔发生,指向异步进程的问题,有时候重新加载页面没有完成。

I solved my debugging tasks by switching to the use of console.log() . 我通过切换到console.log()的使用来解决我的调试任务。 But I'm quite interested what error exactly occurs and how I could avoid it to return to my bad style of debugging by using the alert() function. 但是我非常感兴趣的是错误究竟发生了什么以及如何通过使用alert()函数来避免它返回到我糟糕的调试方式。

嘿(:我在这个论坛上找到了你的问题的可能解释( https://teamtreehouse.com/forum/anyone-else-getting-error-cannot-read-property-impl-of-undefined )。我引用:'在访问属性impl之前返回undefined。由于它是间歇性发生的,这告诉我,privates(port)是一个异步操作 - 允许其他代码继续执行 - 有时私有将在访问属性impl之前完成,有时它不会。'结束语。即使它只是一种猜测,我发现它是理性的

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

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