[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(page-functions): don't try to clone a ShadowRoot #9079

Merged
merged 9 commits into from
Jun 7, 2019
Prev Previous commit
ShadowRoot
  • Loading branch information
brendankenny committed Jun 7, 2019
commit cbd0e4818e07262e384d21510fa441f34aa08eed
6 changes: 4 additions & 2 deletions lighthouse-core/lib/page-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@ function getElementsInDocument(selector) {

/**
* Gets the opening tag text of the given node.
* @param {Element} element
* @param {Element|ShadowRoot} element
* @param {Array<string>=} ignoreAttrs An optional array of attribute tags to not include in the HTML snippet.
* @return {string}
*/
/* istanbul ignore next */
function getOuterHTMLSnippet(element, ignoreAttrs = []) {
try {
if (element instanceof ShadowRoot && element.host && element.localName !== 'a') {
// ShadowRoots are sometimes passed in; use their hosts' outerHTML.
if (element instanceof ShadowRoot) {
element = element.host;
}

Expand All @@ -126,6 +127,7 @@ function getOuterHTMLSnippet(element, ignoreAttrs = []) {
const match = clone.outerHTML.match(reOpeningTag);
return (match && match[0]) || '';
} catch (_) {
// As a last resort, fall back to localName.
return `<${element.localName}>`;
Copy link
Collaborator
@connorjclark connorjclark Jun 3, 2019

Choose a reason for hiding this comment

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

can this entire range fail? if it's just the clone, could you reduce the try/catch to just that part?

a comment in the catch block would be useful.

}
}
Expand Down