Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading