I'm trying to make a simple chrome extension that autofills a particular form but I keep getting
in the chrome extension error log and
in the console.
Here's the popuup.html:
manifest.json
popup.js
Code:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'query')
Code:
Uncaught TypeError: document.getElementsByName(...).setAttribute is not a function
Here's the popuup.html:
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Form 8949</title>
<link rel="stylesheet" href="button.css">
</head>
<body>
<div>
<p>Fill Your IRS Form!</p> <br><br>
<button id="populateIt" name="button">Populate Fields</button>
</div><br><br>
<script src="popup.js"></script>
</body>
</html>
Code:
{
"name": "Automate IRS Form",
"description": "AutoComplete Your IRS Form!",
"version": "1.1",
"action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "Automate IRS Form"
},
"content_scripts": [{
"css": ["button.css"],
"js": ["popup.js"],
"matches": ["<all_urls>"],
"run_at": "document_end"
}],
"manifest_version": 3,
"permissions": ["activeTab", "scripting"]
}
Code:
document.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({active: true, currentWindow:true})
chrome.scripting.executeScript({
target: {tabId: tab.id},
function: () => {
document.getElementsByName('txtDescrip1').setAttribute('value', '1.00 PUT ARCTURUS THERAPEUTIC$30 EXP 01/15/21');
document.getElementsByName('passwd').setAttribute('value', '2823');
document.getElementsByName('txtAcqDate1').setAttribute('value', '12/29/2020');
document.getElementsByName('txtSaleDate1').setAttribute('value', '1/4/2021');
document.getElementsByName('txtSalesPrice1').setAttribute('value', '24.35');
document.getElementsByName('txtBuyPrice1').setAttribute('value', '2823');
document.getElementsByName('txtCode1').setAttribute('value', '0');
document.getElementsByName('txtAmtOfAdj1').setAttribute('value', '0');
document.getElementsByName('txtCapGainOrLoss1').setAttribute('value', 'Short Term');
}
})
});