-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason we don't always do the In devtools:
In standalone:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes
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 = { | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok
It doesn't render if placed after |
||
}); | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope.
lh-report
is insidelh-container
.standalone report:
CDT:
There was a problem hiding this comment.
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.