chrome extension command passing to content script

I would like to implement a hotkey that triggers a function in my content script. The content script (main.js) is executed on page laod from my popup.js file.

i have added the command into my manifest.json and when I add the onCommand listener to my popup.js I can console log that it gets triggered when I press my hotkey (Ctrl+Shift+K)

However I can not get it passed to my content script.

manifest.json

{
    "manifest_version": 2,
    "name": "Ccghjj",
    "description": "hdjdjdjsjs",
    "version": "1.0",
    "browser_action": {
        "default_icon": "icon.png",
        "default_popup": "popup.html"
    },
    "permissions": ["tabs", "*storage", "activeTab"],
    "content_scripts": [
        {
            "matches": ["*://"],
            "css": ["style.css"],
            "js": ["jquery.js", "main.js"]
        }
    ],
    "content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'",
    "web_accessible_resources": ["toolbar.html", "style.css"],
    "commands": {
        "show_deals": {
            "suggested_key": {
                "default": "Ctrl+Shift+K"
            },
            "description": "Highlight Deals"
        }
    }
}

popup.js

function registerButtonAction(tabId, button, action) {
    // clicking button will send a message to
    // content script in the same tab as the popup
    button.addEventListener('click', () => chrome.tabs.sendMessage(tabId, { [action]: true }));
}

function setupButtons(tabId) {
    // add click actions to each 3 buttons
    registerButtonAction(tabId, document.getElementById('start-btn'), 'startSearch');
    registerButtonAction(tabId, document.getElementById('deals-btn'), 'startDeals');
    registerButtonAction(tabId, document.getElementById('stop-btn'), 'stopSearch');
}

function injectStartSearchScript() {
    chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
        // Injects JavaScript code into a page
        // chrome.tabs.executeScript(tabs[0].id, { file: 'main.js' });

        // add click handlers for buttons
        setupButtons(tabs[0].id);
    });
}

injectStartSearchScript();


// hotkey command listener
chrome.commands.onCommand.addListener((show_deals) => {
    console.log(`Command "${show_deals}" triggered`);
    // how can I get to main.js to call deals()

});

main.js (content script)

async function deals() {
    // should be fired when I press my hotkey Ctrl+Shift+K

Answer

Use messages like below

popup.js

chrome.commands.onCommand.addListener((show_deals) => {
    console.log(`Command "${show_deals}" triggered`);
    chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
        chrome.tabs.sendMessage(tab.id, { msg: "deals"})
    })
});

and in your content script

if (!window.firstTimeExecuted) {
    window.firstTimeExecuted = true;
    chrome.runtime.onMessage.addListener((data, sender, sendResponse) => {
        if (data.msg == 'deals') {
            deals()
        }
    });
}