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로 이동합니다.누가 도와 주실 수 있습니까?
은 참조 : [당신이 살아 색인화 된 트랜잭션을 유지하려면 어떻게합니까?]를위한 (http://stackoverflow.com/questions/10385364/how-do-you-keep-an-indexeddb-transaction-alive) –