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

84
Visualizações
How to modify URL in loading page?

UPDATE: I realize now that in the scenario described below I will need to be careful of infinite loops since the page being redirected to is the same (minus the added param) as the initial page. Does anyone have any experience with that in Webextensions and can offer any advice on how best to avoid these loops?


I've written a few Webextensions for Firefox before but it's been a few years (a little out of practise). But a new problem has arisen for which I can see no solution except to write my own Webextension.

How would I modify the URL of a page and add a query parameter? I am specifically trying to modify the URL of Google Docs pages and add the query param ?mode=html

So for example, a Google Docs URL might look like: https://docs.google.com/document/d/7Ujfjsd69To7lInXFOdn49nAxLLhfn43fj43JHDTp87/edit

I am looking to create an extension that will modify that URL so it becomes: https://docs.google.com/document/d/7Ujfjsd69To7lInXFOdn49nAxLLhfn43fj43JHDTp87/edit?mode=html

(Obviously I only want this param appended when the URL being loaded matches https://docs.google.com/document/d/*)

Can anyone give me a pointer on how to start that? What extensionAPI function(s) would I need to use to do that? At what point in the lifespan of the request should it happen etc?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Note: requires "webRequest" & "webRequestBlocking" permission plus host permission

// add a listener for https://docs.google.com/document/*
browser.webRequest.onBeforeRequest.addListener(process, {
    urls: ['https://docs.google.com/document/*'],
    types: ['main_frame']
  },
  ['blocking']
);

function process(details) {
  // check it doesn't have mode=html
  if (!details.url.includes('mode=html')) {
    // add &mode=html if URL already has search string, otherwsie ?mode=html
    return {redirectUrl: details.url + (details.url.includes('?') ? '&' : '?') + 'mode=html'};
  }
}
about 4 years ago · Juan Pablo Isaza Relatório
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