tInterface.html
<body>
<p>Enter User ID</p>
<input type="text" id = "userid" value= "AAA123">
<p>Enter Password</p>
<input type="text" id = 'password' value= "AAA123">
<script src="tInterface.js"></script>
</body>
let params = {
active: true,
currentWindow: true,
};
function sendMessageToTab(message) {
chrome.tabs.query(params, function (e) {
console.log(e[0]);
chrome.tabs.sendMessage(e[0].id, message);
});
}
document.addEventListener("DOMContentLoaded", function () {
// function 1 =>
sendMessageToTab(document.getElementById("userid").value);
//function 2 = >
sendMessageToTab(document.getElementById("userid"));
function 1 logs correctly AAA123
function 2 logs empty object {}, when i want it to log an element like it normally does outside of a chrome extension.
result when i use getElementById() on the html page outside of chrome extension
document.getElementById('userid')
// logs =>
<input type="text" id="userid" placeholder="AAA123">
Does anyone know what is wrong with my code?