Replace to local javascript file when page load using chrome extension manifest v3

53 Views Asked by At

I want to run my local javascript file instead of server's file. I'm using manifest v3 on Chrome extension.

My manifest.json:

{
    "manifest_version": 3,
    "name": "Replace js",
    "description": "",
    "version": "1.0",
    "content_scripts": [
        {
            "js": [
                "content-script.js"
            ],
            "matches": [
                "https://mine.com/*"
            ]
        }
    ],
    "background": {
        "service_worker": "background.js"
    },
    "action": {
      "default_popup": "popup.html"
    },
    "permissions": [
        "declarativeNetRequest",
        "declarativeNetRequestFeedback",
        "webRequest",
        "scripting",
        "activeTab"
    ],
    "host_permissions": [
        "*://www.mine.com/*"
    ]
}

And background.js file

chrome.webRequest.onBeforeRequest.addListener(
    function (details) {
        if (details.url == "https://www.mine.com/remote.js")
            // run my file
    },
    { urls: ["*://www.mine.com/*.js"] },
    ["blocking"]
);

But onBeforeRequest is deprecated in manifest v3

Could anyone help me?

0

There are 0 best solutions below