javascript - Continue in onBeforeRequest - Stack Overflow

admin2025-04-28  2

I have this code in my extension which keeps track what URLs were visited, and how many times, and then it changes the proxy credentials after reaching the limit:

chrome.webRequest.onBeforeRequest.addListener(
    function (details) {
        if (details.method === "GET" && details.type === "main_frame") {
            for (let state_iin in states) {
                if (details.url.indexOf(states[state_iin].url) !== -1) {
                    if (states[state_iin].counter === states[state_iin].limit) {
                        let options = {};
                        const rootDomain = 'my.proxy.server'; // for example domain
                        options.origins = [];
                        options.origins.push("http://" + rootDomain);
                        options.origins.push("https://" + rootDomain);

                        let types = {"cookies": true};
                        chrome.browsingData.remove(options, types, function () {
                            // some code for callback function
                        });
                        states[state_iin].counter = 0
                        return {}
                    }

                    states[state_iin].counter++
                    return {}
                }
            }
        }
    },
    {urls: ["<all_urls>"]},
);

It works only until the time the invocation of chrome.browserData.remove is made - there it just stays on the page, doesn't load the URL or refresh the page.

I'm not sure what to do to make it continue after browsing data was cleared - tried to redirect to same URL but it doesn't work. What do I need to add in order to avoid this kind of behavior? How do I make it continue through request life cycle so that it continues loading the page as usual?

转载请注明原文地址:http://anycun.com/QandA/1745778856a91171.html