@percy/dom 1.22.0-alpha.0 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/bundle.js +18 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ const domSnapshot = await page.evaluate(() => PercyDOM.serialize(options))
|
|
|
37
37
|
|
|
38
38
|
- `enableJavaScript` — When true, does not serialize some DOM elements
|
|
39
39
|
- `domTransformation` — Function to transform the DOM after serialization
|
|
40
|
-
- `
|
|
40
|
+
- `disableShadowDOM` — disable shadow DOM capturing, this option can be passed to `percySnapshot` its part of per-snapshot config.
|
|
41
41
|
|
|
42
42
|
## Serialized Content
|
|
43
43
|
|
package/dist/bundle.js
CHANGED
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
warnings,
|
|
61
61
|
resources,
|
|
62
62
|
enableJavaScript,
|
|
63
|
-
|
|
63
|
+
disableShadowDOM
|
|
64
64
|
} = _ref;
|
|
65
65
|
for (let frame of dom.querySelectorAll('iframe')) {
|
|
66
66
|
var _clone$head;
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
domTransformation: setBaseURI,
|
|
87
87
|
dom: frame.contentDocument,
|
|
88
88
|
enableJavaScript,
|
|
89
|
-
|
|
89
|
+
disableShadowDOM
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
// append serialized warnings and resources
|
|
@@ -159,7 +159,7 @@
|
|
|
159
159
|
function uid() {
|
|
160
160
|
return `_${Math.random().toString(36).substr(2, 9)}`;
|
|
161
161
|
}
|
|
162
|
-
function markElement(domElement,
|
|
162
|
+
function markElement(domElement, disableShadowDOM) {
|
|
163
163
|
var _domElement$tagName;
|
|
164
164
|
// Mark elements that are to be serialized later with a data attribute.
|
|
165
165
|
if (['input', 'textarea', 'select', 'iframe', 'canvas', 'video', 'style'].includes((_domElement$tagName = domElement.tagName) === null || _domElement$tagName === void 0 ? void 0 : _domElement$tagName.toLowerCase())) {
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
// add special marker for shadow host
|
|
172
|
-
if (!
|
|
172
|
+
if (!disableShadowDOM && domElement.shadowRoot) {
|
|
173
173
|
domElement.setAttribute('data-percy-shadow-host', '');
|
|
174
174
|
if (!domElement.getAttribute('data-percy-element-id')) {
|
|
175
175
|
domElement.setAttribute('data-percy-element-id', uid());
|
|
@@ -341,7 +341,7 @@
|
|
|
341
341
|
function cloneNodeAndShadow(_ref) {
|
|
342
342
|
let {
|
|
343
343
|
dom,
|
|
344
|
-
|
|
344
|
+
disableShadowDOM
|
|
345
345
|
} = _ref;
|
|
346
346
|
// clones shadow DOM and light DOM for a given node
|
|
347
347
|
let cloneNode = (node, parent) => {
|
|
@@ -353,12 +353,17 @@
|
|
|
353
353
|
};
|
|
354
354
|
|
|
355
355
|
// mark the node before cloning
|
|
356
|
-
markElement(node,
|
|
356
|
+
markElement(node, disableShadowDOM);
|
|
357
357
|
let clone = node.cloneNode();
|
|
358
358
|
parent.appendChild(clone);
|
|
359
359
|
|
|
360
|
+
// shallow clone should not contain children
|
|
361
|
+
if (clone.children) {
|
|
362
|
+
Array.from(clone.children).forEach(child => clone.removeChild(child));
|
|
363
|
+
}
|
|
364
|
+
|
|
360
365
|
// clone shadow DOM
|
|
361
|
-
if (node.shadowRoot && !
|
|
366
|
+
if (node.shadowRoot && !disableShadowDOM) {
|
|
362
367
|
// create shadowRoot
|
|
363
368
|
if (clone.shadowRoot) {
|
|
364
369
|
// it may be set up in a custom element's constructor
|
|
@@ -386,16 +391,14 @@
|
|
|
386
391
|
/**
|
|
387
392
|
* Use `getInnerHTML()` to serialize shadow dom as <template> tags. `innerHTML` and `outerHTML` don't do this. Buzzword: "declarative shadow dom"
|
|
388
393
|
*/
|
|
389
|
-
function getOuterHTML(
|
|
390
|
-
const docElement = ctx.clone.documentElement;
|
|
394
|
+
function getOuterHTML(docElement) {
|
|
391
395
|
// firefox doesn't serialize shadow DOM, we're awaiting API's by firefox to become ready and are not polyfilling it.
|
|
392
396
|
if (!docElement.getInnerHTML) {
|
|
393
397
|
return docElement.outerHTML;
|
|
394
398
|
}
|
|
395
399
|
// chromium gives us declarative shadow DOM serialization API
|
|
396
|
-
|
|
397
400
|
let innerHTML = docElement.getInnerHTML({
|
|
398
|
-
includeShadowRoots:
|
|
401
|
+
includeShadowRoots: true
|
|
399
402
|
});
|
|
400
403
|
docElement.textContent = '';
|
|
401
404
|
return docElement.outerHTML.replace('</html>', `${innerHTML}</html>`);
|
|
@@ -451,7 +454,7 @@
|
|
|
451
454
|
|
|
452
455
|
// Serializes and returns the cloned DOM as an HTML string
|
|
453
456
|
function serializeHTML(ctx) {
|
|
454
|
-
let html = getOuterHTML(ctx);
|
|
457
|
+
let html = getOuterHTML(ctx.clone.documentElement);
|
|
455
458
|
// replace serialized data attributes with real attributes
|
|
456
459
|
html = html.replace(/ data-percy-serialized-attribute-(\w+?)=/ig, ' $1=');
|
|
457
460
|
// include the doctype with the html string
|
|
@@ -488,7 +491,7 @@
|
|
|
488
491
|
enableJavaScript = options === null || options === void 0 ? void 0 : options.enable_javascript,
|
|
489
492
|
domTransformation = options === null || options === void 0 ? void 0 : options.dom_transformation,
|
|
490
493
|
stringifyResponse = options === null || options === void 0 ? void 0 : options.stringify_response,
|
|
491
|
-
|
|
494
|
+
disableShadowDOM = options === null || options === void 0 ? void 0 : options.disable_shadow_dom
|
|
492
495
|
} = options || {};
|
|
493
496
|
|
|
494
497
|
// keep certain records throughout serialization
|
|
@@ -497,7 +500,7 @@
|
|
|
497
500
|
warnings: new Set(),
|
|
498
501
|
cache: new Map(),
|
|
499
502
|
enableJavaScript,
|
|
500
|
-
|
|
503
|
+
disableShadowDOM
|
|
501
504
|
};
|
|
502
505
|
ctx.dom = dom;
|
|
503
506
|
ctx.clone = cloneNodeAndShadow(ctx);
|
|
@@ -513,7 +516,7 @@
|
|
|
513
516
|
console.error(errorMessage);
|
|
514
517
|
}
|
|
515
518
|
}
|
|
516
|
-
if (!
|
|
519
|
+
if (!disableShadowDOM) {
|
|
517
520
|
injectDeclarativeShadowDOMPolyfill(ctx);
|
|
518
521
|
}
|
|
519
522
|
let result = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/dom",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"interactor.js": "^2.0.0-beta.10"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "cd9a0de3f51233e414cd2657997ce02e8faa19e2"
|
|
38
38
|
}
|