Message from background-script to content-script

I want to be able to send a message from my background-script to my content-script, but wont work.

I get these errors:

Error: Incorrect argument types for tabs.sendMessage. background-script.js:27:16
Unchecked lastError value: Error: Could not establish connection. Receiving end does not exist.
Error: Error: Could not establish connection. Receiving end does not exist.

This is my code (copied from MDN):

browser.windows.onFocusChanged.addListener(event => update(event.tabId))                    
browser.tabs.onActivated.addListener(event => update(event.tabId)) 

async function update(tabId) {

  browser.tabs.sendMessage(
    tabId,
    {greeting: "Hi from background script"}
  ).then(response => {
    console.log("Message from the content script:");
    console.log(response.response);
  }).catch(onError);

  function onError(error) { console.error(`Error: ${error}`) }
}

I’d assume that’s when the tabId refers to an ID that you can’t send a message to

These errors mean that at the time that you sent the message there was no content script listening for messages in that tab.