Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
Chrome Extension - Function to swap domain in URL

I'm totally new to javascript and chrome extensions, I'm sorry for any stupid questions.

I'm building a simple chrome extension (no UI) that will replace api.website.com with test.website.com, anytime a link is clicked or url is entered containing api.website.com.

I'm trying to maintain any additional text or slugs after api.website.com too.

For example:

  • api.website.com/testing/slug

becomes

  • test.website.com/testing/slug

I'm trying to use chrome.webRequest.onBeforeRequest.addListener from this page because it seems quick and efficient.

I'm also trying to use parts from each of these pages:

  • Extract and change URL
  • Fastest method to replace instances in a string

manifest.json

    {
      "name": "Domain Redirect",
      "description": "Replace domain in urls",
      "version": "1.0.0",
      "minimum_chrome_version": "9",
      "manifest_version": 2,
      "background": {
        "scripts": ["background.js"]},
      "permissions": [
        "webRequest",
        "*://api.website.com/"
      ]
    }

background.js

var host = "api.website.com";
chrome.webRequest.onBeforeRequest.addListener(
    function(details) {
         return {redirectUrl: host + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1]};
    },
    {
        urls: [
            "*://api.website.com/"
        ],
        types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
    },
);

I'm not sure where to put test.website.com in the code or how to proceed with the redirect after replacing the domain in the url. I appreciate any insight anyone's willing to offer.

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda