JavaScript - расширение Chrome Как использовать querySelector в addEventListener?
Я пытаюсь использовать этот код в сценарии содержимого расширения Chrome
Ebay.js
copyBtnImage.addEventListener("click", function() {
document.querySelector("#priceblock_ourprice").innerText = 0;
})
AmazonCopyButton.js
const copyBtnImage = document.createElement('img');
copyBtnImage.src = "https://www.akinbaba.com/copyBtn.png";
copyBtnImage.id = "btn";
document.getElementById('leftCol').appendChild(copyBtnImage);
manifest.json
{
"name": "Akinbaba - The New Future of DropShipping!",
"description": "Akinbaba - Lister and Monitor To Facebook Marketplace",
"version": "1.0",
"manifest_version": 2,
"background": {
"scripts": ["./background.js"]
},
"permissions": [
"activeTab",
"tabs",
"storage"
],
"icons": {
"16": "./assets/images/icon16.png",
"48": "./assets/images/icon48.png",
"128": "./assets/images/icon128.png"
},
"browser_action": {
"default_icons": {
"16": "./assets/images/icon16.png",
"48": "./assets/images/icon48.png",
"128": "./assets/images/icon128.png"
}
},
"options_page": "./options.html",
"content_scripts": [
{
"matches": [
"https://www.amazon.co.uk/*",
"https://www.amazon.com/*",
"https://ebay.com/*",
"https://ebay.co.uk/*"
],
"js": ["./assets/js/Amazon/AmazonCopyProductData.js", "./assets/js/Amazon/AmazonCopyButton.js", "./assets/js/Ebay.js"],
"css": ["./assets/css/copyBtn.css"]
}
]
}
ОШИБКА: Uncaught TypeError: невозможно прочитать свойство innerText, имеющее значение null
Этот код работает в консоли Chrome, но не работает в коде сценария содержимого расширения Chrome.