Here is how I got it to work.
$ npm install --save @types/chrome
In angular ts file:
///<reference types="chrome"/> // This might have to be the first line of the file
chrome.runtime.onMessage.addListener((event: any) => {
const message = event.message;
console.log('Message from parent:', message);
}
});
In background service worker:
chrome.runtime.sendMessage({message: json_message});