-1

I want to check if I am in certain domain, like this (in manifest.json for chrome extensions):

"content_scripts": [
{
  "matches": ["*://certain.site/*"],
  "js": ["some.js"]
}

But it seems like there are only dirty ways in javascript, like .split("/") which I don't want to use. Is there a clean way to do it?

CrazyRiot0
  • 31
  • 3

2 Answers2

0

You can use the URL interface for that. Like:

const currentUrl = new URL(window.location.href);

Now you can get the things like path and hostname from the currentUrl, like currentUrl.pathname.

To get only the file name you now can do: currentUrl.pathname.split('/').pop()

Gabe
  • 2,168
  • 2
  • 4
  • 16
0

you get detail of URL

console.log(location);

get current url

console.log(location.href);
dılo sürücü
  • 3,821
  • 1
  • 26
  • 28