For this Chrome extension, any DOM element I try to retrieve comes back as null. I’ve tried a few different websites and tried retrieving DOM elements through ID, class, and name. Below is the latest attempt on wikipedia.org
manifest.json
{
"manifest_version": 3,
"name": "Test",
"version": "1.0",
"description": "testing",
"content_scripts": [
{
"run_at": "document_end",
"js": ["scripts/content.js"],
"matches": [
"*://*.wikipedia.org/*",
"*://wikipedia.com/*"
]
}
],
"action": {
"default_popup": "hello.html"
}
}
hello.html
<html>
<body>
<h1>Hello Extensions</h1>
<script src="./scripts/content.js"></script>
</body>
</html>
content.js
document.addEventListener('DOMContentLoaded', function() {
const domElem = document.getElementById('www-wikipedia-org')
console.log(domElem);
});
window.onload = function() {
const domElem = document.getElementById('www-wikipedia-org')
console.log(domElem);
}