0

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.

2
  • There's no way. Try making an http/https proxy instead. Commented Oct 12, 2023 at 13:01
  • @wOxxOm Can you please elaborate or any example to understand it Commented Oct 12, 2023 at 15:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.