'Getting window object with chrome extension

I am trying to get the window object in a chrome extension. Disclaimer: I'm a beginner.

So, if I go to the chrome console and type console.log(window), this will print me the window object. But if I do console.log(window) in my background.js, I will get the error Uncaught ReferenceError: window is not defined.

What am I doing wrong ??

Also, this is my manifest.json:

{
    "manifest_version": 3,
    "name": "test",
    "version": "1.0",
    "permissions": [
        "tabs"
    ],
    "host_permissions": [
        "*://*.mysite.com/*"
    ],
    "content_scripts":[
        {
            "matches": [
                "<all_urls>"
            ],
            "js": ["background.js"]
        }
    ]
}

Thanks for your help !



Solution 1:[1]

After some further research I found the solution:

use document.defaultView

https://developer.mozilla.org/fr/docs/Web/API/Document/defaultView

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hmngwn