Я только начал изучать JS несколько недель назад и пытаюсь создать расширение для Chrome.Я создал файл manifest.json
, popup.html
, popup.js
и content.js
.
Когда я пытаюсь запустить консоль фоновой страницы в Chrome, чтобы проверить, работает ли popup.js
, я продолжаюполучаю ошибку:
Uncaught TypeError: Cannot read property 'addEventListener' of null
at popup.js:8
Я пытался переместить скрипт в html внизу тела, но он все равно заканчивается ошибкой и пытался реализовать:
document.addEventListener('DOMContentLoaded', function () {
// My code here.. ( Your code here )
});
в моем popup.js
и windows.onload
методе, но все еще не удалось избавиться от ошибки.
Если кто-то может указать на любые ошибки в моем коде и сказать мне, что не такЯ был бы очень признателен.Спасибо
POPUP HTML
<!DOCTYPE html>
<html>
<head>
<title>Like IG Links</title>
</head>
<body>
<h3><center>Paste Links Below</center></h3>
<hr>
<textarea rows="10" cols="60" id="urls"></textarea>
<br>
<textarea rows="1" cols="5" id="counter" disabled></textarea>
<br>
<br>
<button type="submit" align="center" style="width:60px;"
id="start">Start</button>
<br>
<br>
<button type="submit" align="right" style="width:60px;"
id="stop">Stop</button>
<script type="text/javascript" src="popup.js"></script>
</body>
</html>
СОДЕРЖАНИЕ JS
console.log('CHROME');
POPUP JS
console.log('background running');
function loadUrls() {
console.log("123");
}
var startbutton = document.getElementById("start");
startbutton.addEventListener('click', loadUrls);
MANIFEST JSON
{
"manifest_version": 2,
"name": "Like IG Links",
"version": "1.0",
"description": "Like IG Links",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["content.js"]
}
],
"background": {
"scripts": ["popup.js"]
},
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": ["tabs", "storage", "activeTab"]
}