(The question that this was closed for being a duplicate of does not answer my question; I need more help) I am trying to access the DOM for the website a user is using from a chrome extension. What I am trying to do is get the innerText from one element in the DOM using it's class name and then display it in the chrome extension window. Thanks for your help in advance! My code is listed below:
script.js
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var variableOne = document.querySelector('.className').innerText;
document.querySelector('#test').innerText = variableOne;
})
manifest.json
{
"name": "Name",
"description": "Description",
"version": "1.0",
"manifest_version": 3,
"permissions": ["storage", "activeTab", "scripting", "tabs"],
"host_permissions": [
"*://*.example.com/*"
],
"content_scripts": [
{
"matches": ["*://*.example.com/*"],
"js": ["content_script.js"]
}
],
"action": {
"default_popup": "popup.html"
}
}
popup.html
<!DOCTYPE html>
<html>
<head>
<title>Chrome Extension</title>
<meta charset="utf-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-3" style="width: 450px;">
<h2 class="text-center">Chrome Extension</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>One</th>
<th>Two</th>
<th>Three</th>
<th>Four</th>
</tr>
</thead>
<tbody>
<tr>
<td id="test"></td>
<td id="one"></td>
<td id="two"></td>
<td id="three"></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
<script src="script.js"></script>