mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-12 06:06:37 +03:00
Fix live detector empty state (#190)
* Fix live detector empty state * Fix live detector stale scan results
This commit is contained in:
@@ -1437,13 +1437,20 @@ if (IS_BROWSER) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function postSerializedFindings(groupMap) {
|
||||
function scanResultMeta(options = {}) {
|
||||
const scanId = options.scanId;
|
||||
if (typeof scanId !== 'string' && typeof scanId !== 'number') return {};
|
||||
return { scanId: String(scanId) };
|
||||
}
|
||||
|
||||
function postSerializedFindings(groupMap, options = {}) {
|
||||
if (!EXTENSION_MODE) return;
|
||||
const allFindings = browserFindingsFromMap(groupMap);
|
||||
window.postMessage({
|
||||
source: 'impeccable-results',
|
||||
findings: serializeFindings(allFindings),
|
||||
count: allFindings.length,
|
||||
...scanResultMeta(options),
|
||||
}, '*');
|
||||
}
|
||||
|
||||
@@ -1497,7 +1504,7 @@ if (IS_BROWSER) {
|
||||
rememberVisualContrastAnalysis(result);
|
||||
const added = addVisualContrastResult(groupMap, result, { decorate: true });
|
||||
if (added) {
|
||||
postSerializedFindings(groupMap);
|
||||
postSerializedFindings(groupMap, options);
|
||||
window.dispatchEvent(new CustomEvent('impeccable-visual-contrast-resolved', {
|
||||
detail: {
|
||||
selector: result.selector,
|
||||
@@ -1565,7 +1572,7 @@ if (IS_BROWSER) {
|
||||
overlayIndex = 0;
|
||||
}
|
||||
|
||||
function renderBrowserFindings(collected) {
|
||||
function renderBrowserFindings(collected, options = {}) {
|
||||
const { allFindings, pageLevelFindings } = collected;
|
||||
|
||||
for (const { el, findings } of allFindings) {
|
||||
@@ -1585,6 +1592,7 @@ if (IS_BROWSER) {
|
||||
source: 'impeccable-results',
|
||||
findings: serializeFindings(allFindings),
|
||||
count: allFindings.length,
|
||||
...scanResultMeta(options),
|
||||
}, '*');
|
||||
}
|
||||
|
||||
@@ -1599,11 +1607,11 @@ if (IS_BROWSER) {
|
||||
clearOverlays();
|
||||
const generation = scanGeneration;
|
||||
const collected = collectBrowserFindings();
|
||||
const allFindings = renderBrowserFindings(collected);
|
||||
const allFindings = renderBrowserFindings(collected, options);
|
||||
if (shouldRunVisualContrast(options)) {
|
||||
addVisualContrastFindings(collected.groupMap, options, { decorate: true, generation })
|
||||
.then(() => {
|
||||
if (generation === scanGeneration) postSerializedFindings(collected.groupMap);
|
||||
if (generation === scanGeneration) postSerializedFindings(collected.groupMap, options);
|
||||
})
|
||||
.catch(err => {
|
||||
reportVisualContrastError(err);
|
||||
@@ -1618,10 +1626,10 @@ if (IS_BROWSER) {
|
||||
if (shouldRunVisualContrast(options)) {
|
||||
const collected = await collectBrowserFindingsAsync(options, { generation, scheduleLazy: true });
|
||||
if (generation !== scanGeneration) return [];
|
||||
return renderBrowserFindings(collected);
|
||||
return renderBrowserFindings(collected, options);
|
||||
}
|
||||
lastVisualContrastAnalyses = [];
|
||||
return renderBrowserFindings(collectBrowserFindings());
|
||||
return renderBrowserFindings(collectBrowserFindings(), options);
|
||||
};
|
||||
|
||||
const detect = function(options = {}) {
|
||||
|
||||
Reference in New Issue
Block a user