Attempting to append a string to an HTTP request URL

I have been attempting to create a background extension to redirect an HTTP request URL to a target URL that is the original URL + an appended string, but have been running into a few issues and the documentation I have found has not been super helpful.

So far, I managed to get the URL to automatically redirect to the target URL when I do my test as intended as it successfully transforms my URL:

  • from
  • to

But the redirect greets me with this error:

I have been following this tutorial and webRequest.onBeforeRequest documentation to learn how to implement this feature, and have come up with the following code.


window.onload = async () => {
    await browser.tabs.executeScript({file: "/lib/browser-polyfill.min.js"});

let pattern = "*"
const targetUrl = " duck animal"

function redirect(requestDetails) {
    console.log(`Redirecting: ${requestDetails.url}`);
    if (requestDetails.url === targetUrl) {
    return {
        redirectUrl: targetUrl

    {urls:[pattern], types:["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]}, //main_frame - others


  "permissions": [
  "background": {
    "scripts": [

Any idea what I’m doing wrong that is causing the redirect to fail? Any help would be appreciated.

Thanks! :slight_smile: