似乎有时从内容脚本发送的请求会丢失,我猜这种情况会在后台脚本尚未就绪时发生。如何防止这种情况?
谢谢!
修改
这是我目前的解决方法:
// 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);
}