при запуске Chrome происходит сбой расширения - PullRequest
0 голосов
/ 30 марта 2012

Я разработал расширение, которое должно работать в фоновом режиме, и через javascript он запрашивает страницу vbscript, которая возвращает строку JSON. Он работает нормально, когда вы загружаете его вручную.

Моя проблема в том, что в большинстве случаев, когда я захожу на компьютер, расширение вылетает и загружается неправильно Когда я запускаю 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>

`

Спасибо! Lawrence

ОБНОВЛЕНИЕ * Я упростил код вплоть до этого:

<!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"
}
...