How to store fetch headers in javacript from website I don’t own?

I am trying to save headers when a specific fetch is completed on a website I do not own. This is so I can complete a new fetch that requires variables inside the headers that are specific to different users. I found this:

window.fetch = new Proxy(window.fetch, {
    apply(actualFetch, that, args) {
        // Forward function call to the original fetch
        const result = Reflect.apply(actualFetch, that, args);

        // Do whatever you want with the resulting Promise
        result.then((response) => {
            console.log("fetch completed!", args, response);
        });

        return result;
    }
});

But it only seems to work in the browser console. I’m trying to get it working in a chrome extension.

Here’s what I’ve added to the code. Not none of the logs appear in the console. My version works in the browser console as well just not when used in an extension I’m writing.

window.fetch = new Proxy(window.fetch, {
            apply(actualFetch, that, args) {
                console.log('fetchingworking')
                // Forward function call to the original fetch
                const result = Reflect.apply(actualFetch, that, args);

                // Do whatever you want with the resulting Promise
                result.then((response) => {
                    if (args[0].includes('page%22%3A') && args[0].includes('nrte') == false) {
                        console.log('fetchinfoworking')
                        fetchinfo = {
                            urlstart: args[0].split('page%22%3A')[0] + 'page%22%3A',
                            urlend: '%7D%7D&extensions' + args[0].split('%7D%7D&extensions')[1],
                            fetchhead: args[1].headers,
                        }
                    }
                });

                return result;
            }
        })