Question: If I call `console.log('something');` from the popup page, or any script included off that it works fine.

However as the background page is not directly run off the popup page it is not included in the console.

Is there a way that I can get `console.log()`'s in the background page to show up in the console for the popup page?

is there any way to, from the background page call a function in the popup page?

Answer: 
The simplest solution would be to add the following code on the top of the file. And than you can use all full [Chrome console api](https://developers.google.com/chrome-developer-tools/docs/console-api) as you would normally.

```
 console = chrome.extension.getBackgroundPage().console;
// for instance, console.assert(1!=1) will return assertion error
// console.log("msg") ==> prints msg
// etc

```
`chrome.extension.getBackgroundPage()` I get `null`

and accrouding [documentation](https://developer.chrome.com/docs/extensions/mv3/mv3-migration-checklist/),

> 
> Background pages are replaced by service workers in MV3.
> 
> 
> * Replace `background.page` or `background.scripts` with `background.service_worker` in manifest.json. Note that the service\_worker field takes a string, not an array of strings.
> 
> 
> 

manifest.json

```json
{
  "manifest_version": 3,
  "name": "",
  "version": "",
  "background": {
    "service_worker": "background.js"
  }
}

```

anyway, I don't know how to use `getBackgroundPage`, but I found another solution as below,

Solution
--------

use the [chrome.scripting.executeScript](https://developer.chrome.com/docs/extensions/reference/scripting/#runtime-functions)

So you can inject any script or file. You can directly click inspect (F12) and can debug the function.

for example

```js
chrome.commands.onCommand.addListener((cmdName) => {
    switch (cmdName) {
      case "show-alert":
        chrome.storage.sync.set({msg: cmdName}) // You can not get the context on the function, so using the Storage API to help you. // https://developer.chrome.com/docs/extensions/reference/storage/
        chrome.tabs.query({active: true, currentWindow: true}).then(([tab])=>{
          chrome.scripting.executeScript({
            target: {tabId: tab.id},
            function: () => {
              chrome.storage.sync.get(['msg'], ({msg})=> {
                console.log(`${msg}`)
                alert(`Command: ${msg}`)
              })
            }
          })
        })
        break
      default:
        alert(`Unknown Command: ${cmdName}`)
    }
  })

```

I create an [open-source](https://github.com/CarsonSlovoka/chrome/tree/f9d37b5/tutorials/extensions/console-alert) for you reference.