Код: Выделить всё
h.setAttribute('style', 'visibility: hidden;position: absolute; top: 0px; left: -999px;');
Код: Выделить всё
s.style.fontSize = "12px";
РЕДАКТИРОВАТЬ: Ниже приведена ошибка журнала консоли, которую я вижу в Chrome
< р>
Код: Выделить всё
file.js?ts=1731118161084:51 Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self' https://cdn.com". Either the 'unsafe-inline' keyword, a hash ('sha256-Aq7e5LGf4kZTmyqS7SqWaWXFaN/dvBB41GlMIGE1TF8='), or a nonce ('nonce-...') is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the 'unsafe-hashes' keyword is present.
РЕДАКТИРОВАТЬ 3: Добавлен воспроизводимый пример. Я не смог воспроизвести его, используя функцию фрагмента stackoverflow. Итак, вот HTML-код. Вы можете запустить его в HTML-редакторе и получить журнал ошибок в своем браузере.
Код: Выделить всё
Minimal CSP Example
This is a hidden element
// This line will trigger a CSP error because of the inline style
const h = document.getElementById('hidden-element');
h.setAttribute('style', 'visibility: visible');
Код: Выделить всё
h.style.visibility = "visible";
Подробнее здесь: https://stackoverflow.com/questions/791 ... ine-styles