0

chrome.tabs.update() 콜백에서 cursor.continue()를 사용하려고합니다. 나는 항상 다음과 같은 오류가 발생합니다.콜백에서 cursor.continue() 사용

DOM IDBDatabase 예외 0 오류 : 요청이 중 현재 활성화되지 않은 트랜잭션에 넣고, 또는 완성된다.

Error in event handler for 'undefined': TransactionInactiveError: DOM IDBDatabase Exception 0 Error: A request was placed against a transaction which is either currently not active, or which is finished. 
at chrome-extension://fiipdmhnjimefhdbdfpgllkckomakfkh/sample.js:62:20 
at miscellaneous_bindings:288:9 
at chrome.Event.dispatchToListener (event_bindings:390:21) 
at chrome.Event.dispatch_ (event_bindings:376:27) 
at chrome.Event.dispatch (event_bindings:396:17) 
at Object.chromeHidden.Port.dispatchOnMessage (miscellaneous_bindings:254:22)  event_bindings:380 
chrome.Event.dispatch_ event_bindings:380 
chrome.Event.dispatch event_bindings:396 
chromeHidden.Port.dispatchOnMessage 

코드 :

//background.js 
store = getObjectStore(DB_STORE_NAME, 'readwrite'); 
var req; 
req = store.count(); 

req.onsuccess = function(evt) { 
    console.log('<p>There are <strong>' + evt.target.result + 
       '</strong> record(s) in the object store.</p>'); 
       // store = getObjectStore(DB_STORE_NAME, 'readwrite'); 
}; 
req.onerror = function(evt) { 
    console.error("add error", this.error); 
// store = getObjectStore(DB_STORE_NAME, 'readwrite'); 
    //displayActionFailure(this.error); 
}; 

    var i = 0; 
req = store.openCursor(); 
req.onsuccess = function(evt) { 
    cursor = evt.target.result; 
//store = getObjectStore(DB_STORE_NAME, 'readwrite'); 
    // If the cursor is pointing at something, ask for the data 
    if (cursor) { 
    //cursor.advance(i); 
    console.log("rol cursor:", cursor); 
    req = store.get(cursor.key); 
    req.onsuccess = function (evt) {   
    var value = evt.target.result;     
    chrome.tabs.update(cTab.id,{url:value.uri,active:true},function(t){   
     console.log(value.uri,value.path);  
     chrome.tabs.executeScript(t.id,{file:"/lib/jquery-ui-1.8.6/js/jquery-1.9.0.min.js",runAt:"document_end"},function() { 
     chrome.tabs.executeScript(t.id, { code:"var jClaw = jQuery.noConflict();jClaw('html, body').animate({scrollTop:jClaw('"+value.path+"').offset().top}, 2000);jClaw('"+value.path+"').css({background:'yellow'},1000);",runAt:"document_end"},function(){ 
     chrome.tabs.sendMessage(t.id,value.path,function(response){ 

      cursor.continue(); 
     }); 
     }); 

//cursor.update(cursor.value); 
    }); 
     //cursor.update(cursor.value); 
     //chrome.tabs.sendMessage(t.id,"scrollTo"); 
}); 
    }; 

    // Move on to the next object in store 
    //cursor.continue(); 
    //cursor.update(cursor.value); 

    // This counter serves only to create distinct ids 
    i++; 
    } else { 
    console.log("No more entries"); 
    } 
}; 

나는 열려있는 트랜잭션을 유지하기 위해 다양한 방법을 시도했습니다. 그러나 성공하지 못했습니다.

function getObjectStore(store_name, mode) { 
var tx = dbp.transaction(store_name, mode); 
tx.oncomplete = function(e){ 
    console.log("Transaction Complete"); 
    }; 
    tx.onabort = function(e){ 
    console.log("Transaction Aborted"); 
    }; 
    tx.onerror = function(e){ 
    console.log("Transaction Error"); 
    }; 
    //tx.onsuccess=keepAlive; 
return tx.objectStore(store_name); 
} 

당신은 내가 색인 DB를 반복하고 페이지를 채우기 위해 URL을 사용할 볼 수 있듯이

. 그런 다음 스크립트를 삽입하여 메시지 전달을 사용하여 텍스트를 가져 오려고했습니다. 그러나 callback 외부에 cursor.continue()를 배치하면 chrome.tabs.update가 async이므로 다음 URL로 이동합니다.

누가 도와 주실 수 있습니까?

+0

은 참조 : [당신이 살아 색인화 된 트랜잭션을 유지하려면 어떻게합니까?]를위한 (http://stackoverflow.com/questions/10385364/how-do-you-keep-an-indexeddb-transaction-alive) –

답변

1

색인화 된 거래는 즉시 자동으로 종료된다. 참조 : How do you keep an indexeddb transaction alive?

가 색인화에서 여러 개체를 사용하는 비동기 작업이 먼저 배열로 이러한 개체를 수집해야 할 일. 빠른 코드는 내 대답을 참조하십시오. HTML5 How to tell when IndexedDB cursor is at end. 이 코드는 커서의 모든 단일 객체에 대한 get 요청을 발행하지 않으므로보다 효율적입니다. 결국 cursor.value을 사용하여 커서의 현재 위치에서 직접 개체에 액세스 할 수 있습니다.

당신은 또한 당신의 데이터베이스에있는 각 개체에 대해 일을하는지 얼마나 많은 일을 조사 할 수 있습니다. 이제부터는 매번 jQuery 스크립트를 실행하고있다. 이 값을 chrome.tabs.sendMessage으로 제한하려고합니다.

5

내 생각 엔이 chrome.tabs.update입니다 비동기 함수이다. cursor.continue()은 즉시 호출해야합니다 (예 : 비동기 update 함수가 아님). 당신이 store.get(cursor.key) 필요하지 않습니다

또 다른 지점입니다. 값 커서를 사용하고 있으므로 값은 cursor.value으로 얻을 수 있습니다. 이벤트 리스너 중에 (데이터를 수정하거나 커서를 이동) 하나 이상의 새 작업을 대기하지대로

+0

감사합니다 빠른 답변! 보시다시피 나는 인덱스 된 DB를 반복하고 URL을 사용하여 페이지를 채 웁니다. 그런 다음 스크립트를 삽입하여 메시지 전달을 사용하여 텍스트를 가져 오려고했습니다. 그러나 callback 외부에 cursor.continue()를 배치하면 chrome.tabs.update가 async이므로 다음 URL로 이동합니다. – Pradeep

+1

업데이트를 시작하기 전에 모든 URL을 준비하십시오. –