I am facing an issue with extracting the correct GitHub user profile URL in my browser extension. When I click the button in the extension, I am trying to extract the GitHub username from the URL. However, instead of getting the GitHub profile URL (e.g. https://github.com/username
), I am getting the extension URL (e.g. chrome-extension://nnpclboejedioknhkpmkiniklhkacgbp/index.html
).
Here is the manifest.json File:
{
"manifest_version": 3,
"name": "My Extension",
"version": "1.0.0",
"action": {
"default_popup": "index.html"
},
"content_scripts": [
{
"matches": ["https://www.github.com/*"],
"js": ["/src/scripts.js"]
}
],
"permissions": ["activeTab", "tabs"]
}
I tried using the following code to extract the GitHub username from the URL:
const username = window.location.pathname.split('/')[1];
I expected this code to return the GitHub username from the URL (e.g. username
), but instead, it returned the first path component of the extension URL (e.g. index.html
).
I would appreciate any help or suggestions on how to modify the code to get the correct GitHub user profile URL in my browser extension. Thank you in advance for your help.