Skip to content

Conversation

@pranavz28
Copy link
Contributor

@pranavz28 pranavz28 commented Jan 16, 2026

Problem

Customers migrating from Confluence Server to Cloud with broken macros were unable to take snapshots with Percy. When Confluence pages contain broken macros, Confluence adds chrome-error://chromewebdata/ URIs to the DOM. Percy's DOM serialization creates __serialized__ resource URLs using the page's base URL (document.URL), and if that base URL uses a non-http(s) scheme, the generated resource URLs inherit that scheme (e.g., chrome-error://chromewebdata/__serialized__/uid.png). Percy's upload validation rejects non-http(s) schemes, causing snapshot upload failures.

Jira Ticket: PER-6667

Solution

Modified rewriteLocalhostURL() in @percy/dom to detect and rewrite URLs with non-http(s) schemes to http://render.percy.local. The function now:

  1. Parses the incoming URL
  2. Checks if the protocol is NOT http: or https:
  3. If non-http(s) and have chrome-error protocol, reconstructs the URL as a random URL
  4. Otherwise, applies the existing localhost rewrite logic

This ensures that serialized resources always use valid http(s) schemes, regardless of the page's base URL scheme.

Changes

  • Modified: packages/dom/src/utils.js

    • Updated rewriteLocalhostURL() to handle non-http(s) schemes
    • Preserves pathname, search parameters, and hash fragments when rewriting
  • Modified: packages/dom/test/utils.test.js

    • Added test cases for chrome-error:// schemes
    • Added test cases verifying pathname/search/hash preservation

Testing

  • ✅ All existing tests pass (213 tests)
  • ✅ Linting passes
  • ✅ New test coverage for non-http(s) scheme handling
  • ✅ Verified locally with reproduction case

Impact

  • Affected Products: Percy Visual Testing (all SDKs that use @percy/dom)
  • Deployment: No special deployment order required
  • Breaking Changes: None
  • Backwards Compatible: Yes - only affects edge cases with non-http(s) base URLs

- Modified rewriteLocalhostURL() to detect and rewrite non-http(s) schemes
- URLs with schemes like chrome-error://, file://, data:, etc. are now rewritten to http://render.percy.local
- Preserves pathname, search params, and hash when rewriting
- Added comprehensive test coverage for new behavior
- Fixes PER-6667: Snapshots failing when Confluence macros use chrome-error:// scheme
@pranavz28 pranavz28 requested a review from a team as a code owner January 16, 2026 14:16
@pranavz28 pranavz28 changed the title fix: handle non-http(s) URL schemes in DOM serialization (PER-6667) fix: handle non-http(s) URL schemes in DOM serialization Jan 18, 2026
Comment on lines +48 to +53
let parsedURL = new URL(url);

// check if URL has chrome-error scheme and rewrite to a non-existent URL that will 404
if (parsedURL.protocol === 'chrome-error:') {
url = 'http://we-got-a-chrome-error-url-handled-gracefully.com/' + parsedURL.host + parsedURL.pathname + parsedURL.search + parsedURL.hash;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of CLI we should bypass the check in API?, in case any future changes or request comes we will be able to support from API itself without any new release?

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.

3 participants