Skip to content

Conversation

@bs-shobhitkumar
Copy link
Contributor

@bs-shobhitkumar bs-shobhitkumar commented Jan 13, 2026

This pull request introduces a new auto domain allow-listing feature to the Percy client and core, enabling automatic validation and management of external domains accessed during snapshot capture. This helps streamline asset handling by validating domains against project configuration and an external service, and by persisting new discoveries for future builds. The implementation includes changes to both the core logic and the client API, as well as comprehensive tests for the new functionality.

The most important changes are:

Core logic for auto domain allow-listing:

  • Added a domain validation state to the Percy class, including sets for pre-approved, pre-blocked, session-allowed, and session-blocked domains, as well as statistics tracking. (packages/core/src/percy.js)
  • Integrated domain validation checks into the network layer, including logic to check project configuration, session cache, and an external validation service, with fail-open behavior on errors. (packages/core/src/network.js) [1] [2]
  • Updated resource handling to use domain validation results for both blocking and capturing resources. (packages/core/src/network.js) [1] [2]

Project domain configuration persistence:

  • Implemented methods in the Percy class to load project domain config at startup and save newly discovered allowed/blocked domains at shutdown, integrating with the Percy client API. (packages/core/src/percy.js) [1] [2] [3]

Percy client API enhancements:

  • Added a generic patch method and new methods updateProjectDomainConfig and validateDomain to the PercyClient class to support updating project domain configuration and validating domains via an external service. (packages/client/src/client.js) [1] [2]

Test coverage for new features:

  • Added comprehensive tests for updateProjectDomainConfig and validateDomain methods, including positive and negative scenarios and request payload validation. (packages/client/test/client.test.js, packages/client/test/helpers.js) [1] [2]

Wiring and context propagation:

  • Passed the domain validation context and client through the discovery and network layers to ensure the new logic is available where needed. (packages/core/src/discovery.js, packages/core/src/network.js) [1] [2]


// Validate domain for auto-allowlisting feature
// Only validates domains that returned 200 status
async function validateDomainForAllowlist(network, hostname, url, statusCode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

too long function - try to break it down - maybe move to a helper

// Non-200 responses should not be validated
if (
statusCode !== 200 ||
autoConfiguredHosts.has(hostname) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

why should this return null ?

if (result?.error) {
newErrorHosts.add(hostname);
network.log.debug(`Domain validation: ${hostname} validated as BLOCKED - ${result?.reason}`, network.meta);
processedDomains.set(hostname, null);
Copy link
Contributor

@ninadbstack ninadbstack Feb 2, 2026

Choose a reason for hiding this comment

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

shouldn't it set true and false ? why null - using null as falsy is not a good pattern

shouldCapture = true;
log.debug(`- Capturing auto-validated domain: ${hostname}`, meta);
} else {
const domainResult = await validateDomainForAllowlist(network, hostname, url, response.status);
Copy link
Contributor

Choose a reason for hiding this comment

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

this can get triggered in parallel for same domain across multiple requests in current page or across discovery pages, performance isnt handled for that

captureSrcset?: boolean;
devicePixelRatio?: number;
devicePixelRatio?: number;
autoConfigureAllowedHostnames?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

type tests update pending

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.

4 participants