0

我是 Chrome Web Apps 的初学者,正在尝试将 Bump'n'Jump 的 JavaScript/HTML5 克隆打包为打包应用程序。我遇到了 Chrome 的安全策略:

function pump() {
    while (1) {

        game_loop();
        var now = timeGetTime();
        var time_diff = next_time - now;
        next_time += (1000 / 60);

        if (time_diff>0) {
            // we have time left
            setTimeout("pump()", time_diff);
            break;
        }
        // debug("frametime exceeded: " + (-time_diff));
    }
}

它拒绝运行setTimeout("pump()", time_diff);,说

Refused to evaluate script because it violates the following Content Security Policy      directive: "default-src 'self' chrome-extension-resource:". Note that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.

该错误与代码无关,因为它在浏览器中的 Chrome 之外运行,Chrome 的安全性似乎不喜欢它。谁能告诉我为什么它不想运行pump()

4

1 回答 1

4

不知道这是否会有所帮助,但请尝试以下操作:替换setTimeout字符串参数:

function pump() {
    while (1) {

        game_loop();
        var now = timeGetTime();
        var time_diff = next_time - now;
        next_time += (1000 / 60);

        if (time_diff>0) {
            // we have time left
            setTimeout(pump, time_diff);
            break;
        }
        // debug("frametime exceeded: " + (-time_diff));
    }
}

setTimeout使用字符串作为or中的执行参数setInterval等同于evaland 被认为是不好的做法。

于 2012-11-02T06:43:06.460 回答