@percy/dom 1.20.3 → 1.22.0-alpha.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 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
- - `disableShadowDOM` — disable shadow DOM capturing, this option can be passed to `percySnapshot` its part of per-snapshot config.
40
+ - `disableShadowDOMSerialization` — 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
- disableShadowDOM
63
+ disableShadowDOMSerialization
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
- disableShadowDOM
89
+ disableShadowDOMSerialization
90
90
  });
91
91
 
92
92
  // append serialized warnings and resources
@@ -130,13 +130,11 @@
130
130
  let [, ext] = mimetype.split('/');
131
131
  let path = `/__serialized__/${uid}.${ext}`;
132
132
  let url = new URL(path, document.URL).toString();
133
- // converts text to base64
134
- let content = window.btoa(data);
135
133
 
136
- // return the url, base64 content, and mimetype
134
+ // return the url, text content, and mimetype
137
135
  return {
138
136
  url,
139
- content,
137
+ content: data,
140
138
  mimetype
141
139
  };
142
140
  }
@@ -161,7 +159,7 @@
161
159
  function uid() {
162
160
  return `_${Math.random().toString(36).substr(2, 9)}`;
163
161
  }
164
- function markElement(domElement, disableShadowDOM) {
162
+ function markElement(domElement, disableShadowDOMSerialization) {
165
163
  var _domElement$tagName;
166
164
  // Mark elements that are to be serialized later with a data attribute.
167
165
  if (['input', 'textarea', 'select', 'iframe', 'canvas', 'video', 'style'].includes((_domElement$tagName = domElement.tagName) === null || _domElement$tagName === void 0 ? void 0 : _domElement$tagName.toLowerCase())) {
@@ -171,7 +169,7 @@
171
169
  }
172
170
 
173
171
  // add special marker for shadow host
174
- if (!disableShadowDOM && domElement.shadowRoot) {
172
+ if (!disableShadowDOMSerialization && domElement.shadowRoot) {
175
173
  domElement.setAttribute('data-percy-shadow-host', '');
176
174
  if (!domElement.getAttribute('data-percy-element-id')) {
177
175
  domElement.setAttribute('data-percy-element-id', uid());
@@ -343,7 +341,7 @@
343
341
  function cloneNodeAndShadow(_ref) {
344
342
  let {
345
343
  dom,
346
- disableShadowDOM
344
+ disableShadowDOMSerialization
347
345
  } = _ref;
348
346
  // clones shadow DOM and light DOM for a given node
349
347
  let cloneNode = (node, parent) => {
@@ -355,12 +353,12 @@
355
353
  };
356
354
 
357
355
  // mark the node before cloning
358
- markElement(node, disableShadowDOM);
356
+ markElement(node, disableShadowDOMSerialization);
359
357
  let clone = node.cloneNode();
360
358
  parent.appendChild(clone);
361
359
 
362
360
  // clone shadow DOM
363
- if (node.shadowRoot && !disableShadowDOM) {
361
+ if (node.shadowRoot && !disableShadowDOMSerialization) {
364
362
  // create shadowRoot
365
363
  if (clone.shadowRoot) {
366
364
  // it may be set up in a custom element's constructor
@@ -388,14 +386,16 @@
388
386
  /**
389
387
  * Use `getInnerHTML()` to serialize shadow dom as <template> tags. `innerHTML` and `outerHTML` don't do this. Buzzword: "declarative shadow dom"
390
388
  */
391
- function getOuterHTML(docElement) {
389
+ function getOuterHTML(ctx) {
390
+ const docElement = ctx.clone.documentElement;
392
391
  // firefox doesn't serialize shadow DOM, we're awaiting API's by firefox to become ready and are not polyfilling it.
393
392
  if (!docElement.getInnerHTML) {
394
393
  return docElement.outerHTML;
395
394
  }
396
395
  // chromium gives us declarative shadow DOM serialization API
396
+
397
397
  let innerHTML = docElement.getInnerHTML({
398
- includeShadowRoots: true
398
+ includeShadowRoots: !ctx.disableShadowDOMSerialization
399
399
  });
400
400
  docElement.textContent = '';
401
401
  return docElement.outerHTML.replace('</html>', `${innerHTML}</html>`);
@@ -451,7 +451,7 @@
451
451
 
452
452
  // Serializes and returns the cloned DOM as an HTML string
453
453
  function serializeHTML(ctx) {
454
- let html = getOuterHTML(ctx.clone.documentElement);
454
+ let html = getOuterHTML(ctx);
455
455
  // replace serialized data attributes with real attributes
456
456
  html = html.replace(/ data-percy-serialized-attribute-(\w+?)=/ig, ' $1=');
457
457
  // include the doctype with the html string
@@ -488,7 +488,7 @@
488
488
  enableJavaScript = options === null || options === void 0 ? void 0 : options.enable_javascript,
489
489
  domTransformation = options === null || options === void 0 ? void 0 : options.dom_transformation,
490
490
  stringifyResponse = options === null || options === void 0 ? void 0 : options.stringify_response,
491
- disableShadowDOM = options === null || options === void 0 ? void 0 : options.disable_shadow_dom
491
+ disableShadowDOMSerialization = options === null || options === void 0 ? void 0 : options.disable_shadow_dom_serialization
492
492
  } = options || {};
493
493
 
494
494
  // keep certain records throughout serialization
@@ -497,7 +497,7 @@
497
497
  warnings: new Set(),
498
498
  cache: new Map(),
499
499
  enableJavaScript,
500
- disableShadowDOM
500
+ disableShadowDOMSerialization
501
501
  };
502
502
  ctx.dom = dom;
503
503
  ctx.clone = cloneNodeAndShadow(ctx);
@@ -513,7 +513,7 @@
513
513
  console.error(errorMessage);
514
514
  }
515
515
  }
516
- if (!disableShadowDOM) {
516
+ if (!disableShadowDOMSerialization) {
517
517
  injectDeclarativeShadowDOMPolyfill(ctx);
518
518
  }
519
519
  let result = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/dom",
3
- "version": "1.20.3",
3
+ "version": "1.22.0-alpha.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": "520bd156af47080881b651e4819014cbacf76781"
37
+ "gitHead": "5928e586c401ac10840d1ec6219875526e45d100"
38
38
  }