Changing proxy in FindProxyForURL on request

We have a web scraper project that uses different proxies for each of the websites. Currently we’re using this code to return same proxy for each of the websites, but now we need to specify a separate proxy URL for each one:

var config = {
    mode: "pac_script",
    pacScript: {
        data: "function FindProxyForURL(url, host) {n" +
            "    let domainList = ['site1.com', 'site2.com',  'site3.com'];n" +
            "      if (host === 'www.google.com' || host === 'analytics.google.com')" +
            "           return 'PROXY pr.oxylabs.io:7777';" +
            "    for (let i = 0; i < domainList.length; i++) {n" +
            "n" +
            "        if (dnsDomainIs(host, domainList[i])) {n" +
            "            return 'PROXY pr.oxylabs.io:7777';n" +
            "        }n" +
            "    }n" +
            "    if (dnsDomainIs(host, 'analytics.google.com') || dnsDomainIs(host, 'doubleclick.net')) {" +
            "       return 'PROXY 127.0.0.1:65500';n" +
            "}n" +
            "   return 'DIRECT';n" +
            "}"
    }
};

This config is being loaded into browser’ settings via:

chrome.proxy.settings.set({value: config, scope: "regular"}, function () {});

and credentials were provided via:

function callbackFn(details) {
    let username = "custom-username-" + makeid(6);
    return {
        authCredentials: {
            username: username,
            password: "our_password"
        }
    };
}

and then we kept track of how many requests were made to each domain via:

chrome.webRequest.onBeforeRequest.addListener(
    function (details) {
        if (details.method === "GET" && details.type === "main_frame") {
        }
    },
    {urls: ["<all_urls>"]},
);

The question is – how can we assign a different proxy to each domain when, for example, we pass in a magic string in the URL (for example, ___CHANGE___PROXY___FOR___DOMAIN___ZZZ), or something similar to indicate which domain needs a proxy change?

My idea was to create a function that returns contents for FindProxyForURL that generates javascript for it, then put it into config.pacScript.data and call chrome.proxy.settings.set({value: config, scope: "regular"}, function () { })