Skip to content

[MWPW-184883] [Preflight] Added canvas based color contrast checks to preflight#5335

Open
robert-bogos wants to merge 7 commits intostagefrom
184883-preflight
Open

[MWPW-184883] [Preflight] Added canvas based color contrast checks to preflight#5335
robert-bogos wants to merge 7 commits intostagefrom
184883-preflight

Conversation

@robert-bogos
Copy link
Contributor

@robert-bogos robert-bogos commented Jan 19, 2026

@robert-bogos robert-bogos requested a review from a team January 19, 2026 14:52
@robert-bogos robert-bogos self-assigned this Jan 19, 2026
@aem-code-sync
Copy link
Contributor

aem-code-sync bot commented Jan 19, 2026

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-sync branch
Commits

@aem-code-sync aem-code-sync bot temporarily deployed to 184883-preflight January 19, 2026 15:45 Inactive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Copy link
Contributor

@zagi25 zagi25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nits that I noticed right away, will definitely revisit for a more detailed review.

@github-actions
Copy link
Contributor

This pull request is not passing all required checks. Please see this discussion for information on how to get all checks passing. Inconsistent checks can be manually retried. If a test absolutely can not pass for a good reason, please add a comment with an explanation to the PR.

Copy link
Contributor

@mokimo mokimo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll spare the nits, overall you presented the concept and I'd be happy for this to be more of a living-thing and we will collect feedback in the real world about the details.

@skholkhojaev would also include this in his preflight logging - so we could check the pages where we find issues and spot check pages with issues to confirm the whole algorithm and flow works as expected

Comment on lines +21 to +29
const normalized = channel / 255;
return normalized <= 0.03928
? normalized / 12.92
: ((normalized + 0.055) / 1.055) ** 2.4;
};

function extractBgImageUrl(bgImageCss) {
if (!bgImageCss || bgImageCss === 'none') return null;
const match = bgImageCss.match(/url\(["']?([^"')]+)["']?\)/);
return match ? match[1] : null;
}
const relativeLuminance = ([r, g, b]) => (
0.2126 * srgbToLinear(r) + 0.7152 * srgbToLinear(g) + 0.0722 * srgbToLinear(b)
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These magic numbers would benefit from getting moved into variables... I couldn't even fathom where to start to understand where 0.03928 or 12.92 come from, they seem very specific and probably based on some mathematical constants?
Either way, making those a bit more clear might help long term

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are mathematical constants, I am a bit reluctant to move them into variables as they are not and will not be used in more than just one place. I have a comment above though, sending to the link where the math is explained.

Comment on lines +346 to +368
// Step 1: collect visible text nodes, their bounding boxes, and color.
const textElements = collectTextElements(elements);

// Step 2: add visibility hidden to all the text elements, to have a clean DOM for the canvas
hideTextElements(textElements);

// Step 3: capture DOM on canvas
const { base } = getConfig();
await loadScript(`${base}/deps/html2canvas.js`);
const backgroundCanvas = await captureDocumentCanvas();

// Step 4: restore the visibility of the text elements
restoreHiddenText();

// Step 5: Capture a full snapshot, with text visible, for thumbnails
const fullCanvas = await captureDocumentCanvas();

// Step 6: per character from each text node, sample background from textless canvas,
// calculate color contrast, keep the worst ratio per node
applyContrastSampling(textElements, backgroundCanvas, fullCanvas);

// Step 7: create violation entries for low-contrast text nodes
return buildViolations(textElements, minContrast);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love this detailed description,, that's 100% helpful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so happy to know that is useful, I tried to make this as readable as possible ❤️

@aem-code-sync aem-code-sync bot temporarily deployed to 184883-preflight January 26, 2026 09:41 Inactive
@robert-bogos robert-bogos requested a review from zagi25 January 29, 2026 17:20
@NadiiaSokolova NadiiaSokolova self-assigned this Feb 4, 2026
@github-actions
Copy link
Contributor

This PR has not been updated recently and will be closed in 7 days if no action is taken. Please ensure all checks are passing, https://github.com/orgs/adobecom/discussions/997 provides instructions. If the PR is ready to be merged, please mark it with the "Ready for Stage" label.

@github-actions github-actions bot added the Stale label Feb 12, 2026
@github-actions
Copy link
Contributor

Closing this PR due to inactivity.

@github-actions github-actions bot closed this Feb 20, 2026
@robert-bogos robert-bogos reopened this Feb 25, 2026
@github-actions github-actions bot removed the Stale label Feb 26, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

This PR has not been updated recently and will be closed in 7 days if no action is taken. Please ensure all checks are passing, https://github.com/orgs/adobecom/discussions/997 provides instructions. If the PR is ready to be merged, please mark it with the "Ready for Stage" label.

@github-actions
Copy link
Contributor

This PR has not been updated recently and will be closed in 7 days if no action is taken. Please ensure all checks are passing, https://github.com/orgs/adobecom/discussions/997 provides instructions. If the PR is ready to be merged, please mark it with the "Ready for Stage" label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants