如果后台脚本尚未准备好,内容脚本中的sendRequest()是否可能丢失?

时间:2011-12-21 12:48:57

标签: google-chrome-extension

似乎有时从内容脚本发送的请求会丢失,我猜这种情况会在后台脚本尚未就绪时发生。如何防止这种情况?

谢谢!

修改

这是我目前的解决方法:

// This method retries to send the request if response is not received during 1 second:
function sendWaitForResponse(request) {
    var response = null;
    chrome.extension.sendRequest(request, function(r) {
        response = r;
    });
    setTimeout(function() {
        if (!response) {
            sendWaitForResponse(request);
        }
    }, 1000);
}

0 个答案:

没有答案