Вот мой файл манифеста.json:
Код: Выделить всё
{
"name": "Random Stars",
"version": "1.0",
"description": "Randomly assigns stars",
"manifest_version": 3,
"content_scripts": [
{
"matches": [
""
],
"css": [
"style.css"
],
"js": [
"content.js"
]
}
],
"web_accessible_resources": [
{
"resources": [
"star.png"
],
"matches": [ "" ]
}
]
}
Код: Выделить всё
if (window.location.hostname === "") {
const companyNames = document.querySelectorAll('');
companyNames.forEach(companyName => {
const stars = Math.floor(Math.random() * 5) + 1;
const starDiv = document.createElement('div');
starDiv.classList.add('company-stars');
// starDiv.style.backgroundImage = chrome.runtime.getURL("star.png");
starDiv.style.width = `${stars * 20}px`;
companyName.insertAdjacentElement('afterend', starDiv);
});
}
Код: Выделить всё
.company-stars {
display: inline-block;
width: 100px;
height: 20px;
background-image: url("star.png");
background-size: contain;
background-repeat: no-repeat;
background-position: center;
margin-left: 5px;
}
Что я пробовал:
- Мне удалось открыть изображение в Chrome в HTML-файле.
- Я пытался преобразовать стили из style.css в content.js, но это не помогло help
- Используйте только свойство display CSS, но это тоже не помогло
- Я пытался избавиться от изображения URL из CSS и JS файлов (отдельно) - если я избавился от него в CSS, то места изображения там не было, пока оно было при закомментировании фонового изображения в JS файле
- Я убедился, что star.png находится в той же папке, что и content.js, Manifest.json и style.css
- Я также получаю сообщение Uncaught DOMException: не удалось прочитать свойство cookie из ' Документ': документ находится в песочнице и не имеет флага "allow-same-origin", но я не думаю, что это проблема.
Подробнее здесь: https://stackoverflow.com/questions/764 ... -not-shown
Мобильная версия