@percy/dom
Advanced tools
Comparing version 1.31.0-alpha.2 to 1.31.0-alpha.3
@@ -550,11 +550,5 @@ (function() { | ||
*/ | ||
function getOuterHTML(docElement) { | ||
// All major browsers in latest versions supports getHTML API to get serialized DOM | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Element/getHTML | ||
// old firefox doesn't serialize shadow DOM, we're awaiting API's by firefox to become ready and are not polyfilling it. | ||
// new firefox from 128 onwards serializes it using getHTML | ||
/* istanbul ignore if: Only triggered in firefox <= 128 and tests runs on latest */ | ||
if (!docElement.getHTML) { | ||
return docElement.outerHTML; | ||
} | ||
function getOuterHTML(docElement, { | ||
shadowRootElements | ||
}) { | ||
// chromium gives us declarative shadow DOM serialization API | ||
@@ -564,4 +558,7 @@ let innerHTML = ''; | ||
if (docElement.getHTML) { | ||
// All major browsers in latest versions supports getHTML API to get serialized DOM | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Element/getHTML | ||
innerHTML = docElement.getHTML({ | ||
serializableShadowRoots: true | ||
serializableShadowRoots: true, | ||
shadowRoots: shadowRootElements | ||
}); | ||
@@ -572,2 +569,6 @@ } else if (docElement.getInnerHTML) { | ||
}); | ||
} else { | ||
// old firefox doesn't serialize shadow DOM, we're awaiting API's by firefox to become ready and are not polyfilling it. | ||
// new firefox from 128 onwards serializes it using getHTML | ||
return docElement.outerHTML; | ||
} | ||
@@ -600,3 +601,5 @@ docElement.textContent = ''; | ||
function serializeHTML(ctx) { | ||
let html = getOuterHTML(ctx.clone.documentElement); | ||
let html = getOuterHTML(ctx.clone.documentElement, { | ||
shadowRootElements: ctx.shadowRootElements | ||
}); | ||
// replace serialized data attributes with real attributes | ||
@@ -619,2 +622,5 @@ html = html.replace(/ data-percy-serialized-attribute-(\w+?)=/ig, ' $1='); | ||
if (shadowHost.shadowRoot && cloneShadowHost.shadowRoot) { | ||
// getHTML requires shadowRoot to be passed explicitly | ||
// to serialize the shadow elements properly | ||
ctx.shadowRootElements.push(cloneShadowHost.shadowRoot); | ||
serializeElements({ | ||
@@ -665,2 +671,3 @@ ...ctx, | ||
cache: new Map(), | ||
shadowRootElements: [], | ||
enableJavaScript, | ||
@@ -667,0 +674,0 @@ disableShadowDOM |
{ | ||
"name": "@percy/dom", | ||
"version": "1.31.0-alpha.2", | ||
"version": "1.31.0-alpha.3", | ||
"license": "MIT", | ||
@@ -38,3 +38,3 @@ "repository": { | ||
}, | ||
"gitHead": "1c7711f564fd4a112e1e1490a772db757df0535d" | ||
"gitHead": "14ae0b4319c1c2ae28729d56cba3b159e80386a8" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36215
715