扩展程序在Chrome启动时崩溃

时间:2012-03-30 16:14:34

标签: crash google-chrome-extension

我开发了一个应该在后台运行并通过javascript运行的扩展,它会查询返回JSON字符串的vbscript页面。手动加载时运行正常。

我的问题是,大部分时间我登录计算机时,扩展程序崩溃并且无法正确加载。当我启动Chrome并转到扩展程序时,扩展程序显示为灰色并显示(崩溃)。有没有办法错误陷阱或为它写一个日志文件?

我使用的是Chrome版本18.0.1025.142 m。

<!DOCTYPE html>
<html>
<head>

<script language='javascript'>

// jquery Min content

function QueryIDObj(t) {
    this.MAXID = t;
}

$(document).ready( function() {
    var oLastMaxID = new QueryIDObj('');
    var iRefreshTime = 5000;
    createLoadedNotification();
    RetrieveServerData(oLastMaxID, iRefreshTime);
});

function createNotification(result, oLastMaxID){
var jObjResult, sOutput='';

try {
    jObjResult = JSON.parse(result);
    oLastMaxID.MAXID = jObjResult.MAXID;
    var currentTime = new Date();

    console.log('records #'+jObjResult.data.length +' at '+ currentTime);
    console.log('maxID #'+ jObjResult.MAXID);

    if (jObjResult.data.length>0) {
        for(var i=0; i<jObjResult.data.length; i++) {
            var strLink = "https://www.url.com/webpage.asp?requestID="+ jObjResult.data[i].ITEMID;
            var notification = webkitNotifications.createHTMLNotification("http://www.url.com/webpage2.asp?ID="+ jObjResult.data[i].ITEMID);
            notification.onclick = (function(myStrLink){
                return function(){
                    chrome.windows.create({url: myStrLink, focused: true});
                    this.cancel();
                }
            })(strLink);
            notification.show();
        }
    }
}
catch(e) {
    // var notification = window.Notifications.createNotification("", "Error", e.message);
    // notification.show();
    alert("ERROR! You need to check the status of the Chrome Application. "+ e.message);
}
}

function createLoadedNotification(){
try {
    var notification = webkitNotifications.createNotification("","Chrome Application", "The Chrome Application has loaded.");
    notification.show();
}
catch(e) {
    // var notification = window.Notifications.createNotification("", "Error", e.message);
    // notification.show();
    alert("ERROR! You need to restart the Chrome Application. "+ e.message);
}
}

function RetrieveServerData(oLastMaxID, iRefreshTime) {
try {
    $.ajax({
        type: "POST",
        cache: false,
        url: "http://www.url.com/populateJSON.asp",
        data: "prevMaxID="+encodeURI(oLastMaxID.MAXID),
        success: function(result, textStatus, jqXHR){
            createNotification(result, oLastMaxID);
            var newServerCall = setTimeout(function() {RetrieveServerData(oLastMaxID, iRefreshTime)}, iRefreshTime);
                newServerCall = null;
        },
        error: function(jqXHR, textStatus, errorThrown){
            // createErrorNotifiction(errorThrown, oLastMaxID);
            alert("ERROR! You need to restart the Chrome Application. "+ errorThrown);
        }
    });
}
catch(e) {
    // var notification = window.Notifications.createNotification("", "Error", e.message);
    // notification.show();
    alert("ERROR! You need to check the status of the Chrome Application. "+ e.message);
}
// alert("TRYING");
}
</script>

`

谢谢! 劳伦斯

更新 * 我一直将代码简化为:

<!DOCTYPE html>
<html>
<head>

<script language='javascript'>

function createLoadedNotification(){
    try {
    var notification = webkitNotifications.createNotification("","Application", "The Chrome Application has loaded.");
        notification.show();
    }
catch(e) {
    // var notification = window.Notifications.createNotification("", "Error", e.message);
    // notification.show();
    alert("ERROR! You need to restart the Chrome Application. "+ e.message);
}
}

createLoadedNotification();

</script>

</head>
<body>
    <div>
        Info would go here.
    </div>
</body>

</html>

它仍然崩溃了。我的清单文件如下:

{
"name": "App Name",
"description": "Display incoming alerts",
"version": "1",
"icons": {
"128": "icon_128.png"
},
"permissions": [
"tabs",
"notifications",
"background"
],
"background_page": "notification.html"
}

0 个答案:

没有答案