I tried to get the domain name using alert(document.domain); But i’m not getting the right domain when I test it out in a site,
I get “hiecjmnbaldlmopbbkifcelmaaalcfib” this weird output.
I have added this in the manifest too
"content_scripts": [
{
"js": ["inject.js"]
}
],
alert(document.domain); is the only line of text inside inject.js.
And I’ve incorporated this <script type="text/javascript" src="inject.js"> into the main html file after
</script>popup.js
Any thoughts on why I’m not getting the correct domain url?
Thanks!
If you are in popup or background or options page, there is an indirect approach for obtaining domain of page.
You can refer to following code as a reference.
Demonstration
manifest.json
Registered content scripts, background and popup scripts with manifest file along with relevant permissions
myscript.js
popup.html
Registered
popup.jsto surpass CSP.popup.js
Added Event Listener for
DOM Content Loaded, and brought active URL of tab where user is on.background.js
Output
You will find
as output for console.log(document.domain); in all extension pages and
and
for
tabs.query()output.However, Content script output is always
References