[Web Extension]: How to hold url loading till the time Web Extension is processing

42 views Asked by At

My web extension tries to intercept a web request for a particular url, at this point I want to set a cookie for this particular url. The issue i am facing is the lag caused due to delay in getting the cookie via native messaging and due to this lag the url gets loaded while the extension is still waiting to get the cookie via native messaging. Is there a way i can hold the url loaded till the point i receive the cookie.

I think this was possible in MV2, with blocking permissions in webRequest Api but couldnt find anything useful with declrativeNetRequest Api.

Following code snippet.

  const MY_CUSTOM_RULE_ID = 1012;
    console.log(tab);
    var port = chrome.runtime.connectNative("overseas.media.example");
    port.postMessage("Get cookie!!");


    port.onMessage.addListener(async function (message)
        {
            console.log("hello");
            console.log(message.text);
     
            chrome.declarativeNetRequest.updateDynamicRules({
                removeRuleIds: [MY_CUSTOM_RULE_ID],
                addRules: [
                    {
                        id: MY_CUSTOM_RULE_ID,
                        priority: 1,
                        action: {
                            type: "modifyHeaders",
                            requestHeaders: [
                                {
                                    operation: "set",
                                    header: "cookie",
                                    value: message.text
                                }
                            ]
                        },
                        condition: {
                            "urlFilter": url_id,
                            "resourceTypes": ["main_frame", "sub_frame"]
                        },
                    }
                ],
            });

        })

I think this was possible in MV2, with blocking permissions in webRequest Api but couldnt find anything useful with declrativeNetRequest Api.

0

There are 0 answers