Robím automatického dopĺňania a rozšírenie prehliadača chrome. Totiž, akonáhle stlačíte tlačidlo, vstupný formulár v obsahu webovej stránky bude obývaný text z popup.html. Som stále to "nie je možné čítať vlastnosti z null" chyba pri spúšťaní z miesta, kde som pridané udalosť poslucháča do svojho tlačidlo. [Uncaught TypeError: nemôžem čítať vlastnosti null (čítanie "addEventListener')][1]
Tu je môj html súboru
<!DOCTYPE html>
<html lang="en">
<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>Autofill</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<p id="testText">Text to put</p>
<button id="fillForm">Fill!</button>
<script src="app.js" ></script>
</body>
</html>
Tu je môj app.js
console.log('background running!!!')
let testtext = document.getElementById('testText')
let button = document.getElementById('fillForm')
button.addEventListener('click', buttonClick);
function buttonClick(){
params = {
active: true,
currentWindow: true
}
chrome.tabs.query(params, gotTabs);
function gotTabs(tabs){
let text = testtext.innerHTML
let content = {
username: text
}
chrome.tabs.sendMessage(tabs[0].id, content);
}
}
Tu je môj content.js
console.log("Receiving message...")
chrome.runtime.onMessage.addListener(gotMessage);
function gotMessage(message, sender, sendReponse){
document.getElementById('email').value = content.username
}
Napokon, môj manifest.json
{
"name": "Resume Autofiller",
"description": "Build an Extension!",
"version": "1.0",
"manifest_version": 2,
"browser_action":{
"default_popup": "index.html"
},
"permissions": [
"activeTab",
"<all_urls>"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": [ "content.js" ]
}
],
"background": {
"scripts": ["app.js"]
}
}
Ja si on-line že by som mal dať moje značky skriptu v dolnej časti tela značku, ale stále som si to chyba. Mám pocit, že som dohľad nad niečo jasné, preto každá pomoc je veľmi ocenil. Vďaka!! Pripojený je chyba som dostať. [1]: https://i.stack.imgur.com/GyNXO.png