Chrome crx Could not establish connection

Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

Chrome 扩展 sendResponse 返回 undefined (时而返回 undefined 时而返回 成功)

chrome.runtime.onMessage.addListener(function (res, sender, sendResponse) {
    sendResponse('done');
    return true
});

多次尝试发现仅 manifest.json 中 content_scripts 设定的域名可以接受通信,非设定的域名无法通信。

另网页加载过程中通信也会造成返回失败,可以判断 tab 的 status 是否等于 complete,再进行通信