Add a query param using declarativeNetRequest in manifest V3

Viewed 625

manifest.json

{
  "name": "Getting Started Example",
  "description": "Build an Extension!",
  "version": "1.0",
  "manifest_version": 3,
  "background": {
    "service_worker": "background.js"
  },
  "declarative_net_request": {
    "rule_resources": [
      {
        "id": "ruleset_1",
        "enabled": true,
        "path": "rules_1.json"
      }
    ]
  },
  "permissions": [
    "storage",
    "activeTab",
    "scripting",
    "declarativeNetRequest",
    "declarativeNetRequestFeedback"
  ],
  "host_permissions": ["*://example.com/*"],
  "action": {
    "default_popup": "popup.html",
    "default_icon": {
      "16": "/images/get_started16.png",
      "32": "/images/get_started32.png",
      "48": "/images/get_started48.png",
      "128": "/images/get_started128.png"
    }
  },
  "icons": {
    "16": "/images/get_started16.png",
    "32": "/images/get_started32.png",
    "48": "/images/get_started48.png",
    "128": "/images/get_started128.png"
  },
  "options_page": "options.html"
}

rules_1.json

[
  {
    "id": 1,
    "priority": 1,
    "action": {
      "type": "redirect",
      "redirect": {
        "transform": {
          "queryTransform": {
            "addOrReplaceParams": [{ "key": "test", "value": "123" }]
          }
        }
      }
    },
    "condition": {
      "urlFilter": "https://example.com",
      "resourceTypes": ["main_frame"]
    }
  }
]

I am playing around with the example extension code from google, I want to add a query param to an existing url, this work but its clunky because:

  1. I have to navigate to the page
  2. Click the extension and hit a button
  3. Go in the url bar and press enter

Then it adds the query param.

[![url updated][1]][1]

Question:

Is it possible to just add the query param as soon as it hits the url instead of having to do the steps above? [1]: https://i.stack.imgur.com/KH6tY.png

0 Answers
Related