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

204
Views
Chrome extension: How to make my tabs query return the URL without anything after the .com/

I would like to get the URL as the website's domain name rather than having the extra parts after the ".com/"

Currently when I query tabs with chrome.tabs.query(params, function(){...}); the URL will still contain all the content about the specific page rather than just being the website's domain

How should I go about this so that it will also work with .ca or .gov as well? Is there a trick to shrink the string after the domain ends or will I have to look for string patterns in the URL for each different ending

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can parse the result and extract the domain name from it.

let result = 'https://example.com/some/after?=after:stuf&';
const url = new URL(result);
const domain = url.hostname;
console.log(domain);

OUTPUT

example.com
about 4 years ago · Juan Pablo Isaza Report

0

Given Tab.url is a plain string, you can run it through the URL constructor and get the origin from that

// just for the demo
const tabs = [{
  url: "https://stackoverflow.com/questions/73524018/chrome-extension-how-to-make-my-tabs-query-return-the-url-without-anything-afte",
}, {
  url: "https://example.com/foo/bar/baz?msg=Hello%20World",
}];

const origins = tabs.map(({ url }) => new URL(url).origin);
console.log(origins);

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!