В итоге, на основе примера предложенного
denisromanenko получилось такое решение:
(менее глючное, чем в примере)
function getAllCSSVariableNames(styleSheets = document.styleSheets) {
let names1 = [];
for (const sheet1 of styleSheets) {
try {
for (const rule1 of sheet1.cssRules)
if (rule1.cssText.startsWith(':root'))
for (const name1 of rule1.style)
if (names1.indexOf(name1) == -1)
names1.push(name1);
} catch { }
}
return names1;
}
function getElementCSSVariables(names, element = document.body, pseudo) {
let styles1 = window.getComputedStyle(element, pseudo);
let vars1 = {};
for (let i1 = 0; i1 < names.length; i1++) {
let key1 = names[i1];
let value1 = styles1.getPropertyValue(key1)
vars1[key1] = value1;
}
return vars1;
}
const names = getAllCSSVariableNames();
const vars = getElementCSSVariables(names);
const elem1 = document.getElementById('cssVariables');
let s1 = '';
for (let key1 in vars) {
s1 += `<tr><td class="text-nowrap">${key1}</td><td><code>${vars[key1]}</code></td></tr>`;
}
elem1.innerHTML = s1;