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

report: flexible viewport for element screenshot overlay #11843

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions lighthouse-core/report/html/renderer/element-screenshot-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,29 @@ class ElementScreenshotRenderer {
* @param {LH.Artifacts.FullPageScreenshot} fullPageScreenshot
*/
static installOverlayFeature(dom, templateContext, fullPageScreenshot) {
const reportEl = dom.find('.lh-report', dom.document());
const screenshotOverlayClass = 'lh-feature-screenshot-overlay';
if (reportEl.classList.contains(screenshotOverlayClass)) return;
reportEl.classList.add(screenshotOverlayClass);
const topbarEl = dom.find('.lh-topbar', dom.document());
const containerEl = topbarEl.parentElement;
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah so this should be the .lh-report in the standalone report, but might be different in DevTools/PSI?

Copy link
Collaborator Author

@connorjclark connorjclark Dec 16, 2020

Choose a reason for hiding this comment

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

nope. lh-report is inside lh-container.

standalone report:

image

CDT:

image
image

Copy link
Member

Choose a reason for hiding this comment

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

for whatever reason we have a <main> in standalone. and that elem isn't there for devtools. (not sure about PSI, but probably one of those)

we could be normalizing this DOM structure a bit more but.. yah it's currently not.

if (!containerEl) throw new Error('could not find parent element');

const maxLightboxSize = {
width: dom.document().documentElement.clientWidth,
height: dom.document().documentElement.clientHeight * 0.75,
};
const screenshotOverlayClass = 'lh-feature-screenshot-overlay';
if (containerEl.classList.contains(screenshotOverlayClass)) return;
containerEl.classList.add(screenshotOverlayClass);

dom.document().addEventListener('click', e => {
const target = /** @type {?HTMLElement} */ (e.target);
if (!target) return;
const el = /** @type {?HTMLElement} */ (target.closest('.lh-element-screenshot'));
if (!el) return;

const maxLightboxSize = {
width: dom.document().documentElement.clientWidth,
height: dom.document().documentElement.clientHeight * 0.75,
};
if (dom.isDevTools()) {
maxLightboxSize.width = containerEl.clientWidth;
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a reason we don't always do the Math.min of these? is the below correct?

In devtools:

  • the container is the inner area available to our pane
  • the document is the entire devtools area

In standalone:

  • the container is the very tall lh-report element
  • the document is the window

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is the below correct?

yes

is there a reason we don't always do the Math.min of these?

That would work. I find this easier to reason about though. Although using the min would possible benefit other embedders..is that your goal here?

maxLightboxSize.height = containerEl.clientHeight * 0.75;
}

const overlay = dom.createElement('div');
overlay.classList.add('lh-element-screenshot__overlay');
const elementRectSC = {
Expand All @@ -175,11 +182,12 @@ class ElementScreenshotRenderer {
if (!screenshotElement) return;

overlay.appendChild(screenshotElement);
overlay.addEventListener('click', () => {
containerEl.addEventListener('click', () => {
overlay.remove();
});

reportEl.appendChild(overlay);
// Must place after the topbar (but before `lh-container`).
containerEl.insertBefore(overlay, topbarEl.nextElementSibling);
Copy link
Collaborator

Choose a reason for hiding this comment

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

there seems to be significance to the fact that the overlap comes immediately after the topbar. if so, comment? if not, stick with appendChild on the container?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok

if not, stick with appendChild on the container?

It doesn't render if placed after lh-container.

});
}

Expand Down
5 changes: 2 additions & 3 deletions lighthouse-core/report/html/report-styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.