Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda