Google chrome 没有执行我所有的 <script>

Google chrome is not executing all my <script>s

我正在使用 html5、canvas、node 和 socket.io 制作某种在线游戏。我的游戏的 html 包含一个 canvas 标签,然后是标签列表,一些按来源,一些按内联。布局是这样的:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
</head>
<body>

    <canvas id="myCanvas" width="640" height="640" >
        Your browser does not support the HTML5 canvas tag.
    </canvas>

    <!-- Scripts go here -->

</body>
</html>

我的游戏在 firefox 中运行良好,但在 chrome 中它只执行前两个脚本:

<script src="/socket.io/socket.io.js"></script>
<script> 
    if(window.io) {
        var socket = io();
        socket.emit('identify', { client_type : 'game' });
    }
</script>

这两个脚本被正确执行,但在那之后,chrome 只是忽略了所有其他脚本,这些脚本主要是定义函数和常量。例如,像这样的东西:

<script src="vector2.js" type="text/javascript;version=1.7"></script>
<script src="utils.js" type="text/javascript;version=1.7"></script>

我认为值得一提的是我正在使用严格模式和一些 ES6 功能,例如 let,但即使那是问题所在,我也希望在控制台上看到一些输出。相反,我的 console.logs 和任何类型的错误都没有被打印出来。

查看调试器我可以看到前两个脚本是如何执行的,然后它在这段代码中陷入循环(在 -> 指向的行中)。

if (this.hasXDR()) {
    xhr.onload = function(){
        self.onLoad();
    };
    xhr.onerror = function(){
        self.onError(xhr.responseText);
    };
} else {
    xhr.onreadystatechange = function(){
->      if (4 != xhr.readyState) return;
        if (200 == xhr.status || 1223 == xhr.status) {
            self.onLoad();
        } else {
            // make sure the `error` event handler that's user-set
            // does not throw in the same tick and gets caught here
            setTimeout(function(){
                self.onError(xhr.status);

请注意,这段代码不是我写的,我无法真正确定这个库是什么。我只能在循环中告诉它 运行 在这个函数中。

这是怎么回事?为什么我的脚本没有被执行?

我终于明白是怎么回事了。即使到目前为止我还没有找到修复或解决方法。

它与将脚本标记为 javascript 1.7 版有关,这样做会使我的 linux 机器中的 google chrome 和 chromium 完全忽略该脚本。删除该类型属性会使脚本加载。但是浏览器无法正确识别 ES6 功能。

我post这是一个答案,因为它确实回答了我原来的问题,但是非常欢迎更好地回答发生这种情况的原因和可能的修复方法。