Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

82
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!