What you have to do is to handle window.chrome.runtime.lastError in the runtime.sendMessage callback. Just use this code and it will handle that error.
window.chrome.runtime.sendMessage(
EXTENSION_ID,
{ message:"---" }, // jsonable message
(result) => {
if (!window.chrome.runtime.lastError) {
// message processing code goes here
} else {
// error handling code goes here
}
}
);
});
I hope this helps you.