workaround for Chrome devtools bug (fixed in v65)

recreate the style element on style code change because older devtools inspector can't edit injected rules after we update textContent of an existing element
This commit is contained in:
tophf 2018-01-15 19:42:30 +03:00
parent 0f8bca03b8
commit 0fa391732b

View File

@ -6,6 +6,7 @@
// some weird bug in new Chrome: the content script gets injected multiple times // some weird bug in new Chrome: the content script gets injected multiple times
return; return;
} }
const CHROME = chrome.app ? parseInt(navigator.userAgent.match(/Chrom\w+\/(?:\d+\.){2}(\d+)|$/)[1]) : NaN;
var ID_PREFIX = 'stylus-'; var ID_PREFIX = 'stylus-';
var ROOT = document.documentElement; var ROOT = document.documentElement;
var isOwnPage = location.protocol.endsWith('-extension:'); var isOwnPage = location.protocol.endsWith('-extension:');
@ -252,9 +253,16 @@
function applySections(styleId, code) { function applySections(styleId, code) {
const id = ID_PREFIX + styleId; const id = ID_PREFIX + styleId;
let el = styleElements.get(id) || document.getElementById(id); let el = styleElements.get(id) || document.getElementById(id);
if (el) { if (el && el.textContent !== code) {
if (el.textContent !== code) el.textContent = code; if (CHROME < 3321) {
// workaround for Chrome devtools bug fixed in v65
el.remove();
el = null;
} else { } else {
el.textContent = code;
}
}
if (!el) {
if (document.documentElement instanceof SVGSVGElement) { if (document.documentElement instanceof SVGSVGElement) {
// SVG document style // SVG document style
el = document.createElementNS('http://www.w3.org/2000/svg', 'style'); el = document.createElementNS('http://www.w3.org/2000/svg', 'style');