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

#8380: add isInViewport property to element reader #8381

Merged
merged 4 commits into from
May 1, 2024

Conversation

twschiller
Copy link
Contributor

What does this PR do?

Checklist

  • Add jest or playwright tests and/or storybook stories
  • Designate a primary reviewer: @fungairino

Copy link

codecov bot commented Apr 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.48%. Comparing base (afb4f9f) to head (d519b16).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8381      +/-   ##
==========================================
+ Coverage   73.47%   73.48%   +0.01%     
==========================================
  Files        1334     1334              
  Lines       41251    41259       +8     
  Branches     7679     7684       +5     
==========================================
+ Hits        30308    30319      +11     
+ Misses      10943    10940       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Apr 30, 2024

Playwright test results - MV2

passed  33 passed
flaky  1 flaky
skipped  8 skipped

Details

report  Open report ↗︎
stats  42 tests across 16 suites
duration  8 minutes, 2 seconds
commit  d519b16

Flaky tests

edgeSetup › auth.setup.ts › authenticate

Skipped tests

chrome › tests/extensionConsoleActivation.spec.ts › can activate a mod with built-in integration
edge › tests/extensionConsoleActivation.spec.ts › can activate a mod with built-in integration
chrome › tests/runtime/sidebarController.spec.ts › sidebar controller › shows focus dialog in top-level frame
edge › tests/runtime/sidebarController.spec.ts › sidebar controller › shows focus dialog in top-level frame
chrome › tests/runtime/sidebarNavigation.spec.ts › sidebar mod panels are persistent during navigation
chrome › tests/runtime/sidebarNavigation.spec.ts › sidebar form and temporary panels are unavailable after navigation
edge › tests/runtime/sidebarNavigation.spec.ts › sidebar mod panels are persistent during navigation
edge › tests/runtime/sidebarNavigation.spec.ts › sidebar form and temporary panels are unavailable after navigation

Copy link

github-actions bot commented Apr 30, 2024

Playwright test results - MV3

passed  42 passed

Details

report  Open report ↗︎
stats  42 tests across 16 suites
duration  10 minutes, 42 seconds
commit  d519b16

/**
* Returns true if the element is completely in the viewport.
*/
export function isInViewport(element: HTMLElement): boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should note on this method that this doesn't work for elements hidden by z-index overlapped, or if they are hidden by overflow-scroll in element's container. This may also have issues with things hidden by relative/absolute positioning, and if they are within an iframe that is not entirely visible in the top frame.

export function isInViewport(element: HTMLElement): boolean {
// https://stackoverflow.com/a/125106
const rect = element.getBoundingClientRect();
return (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we also check isVisible?

Copy link
Contributor Author

@twschiller twschiller May 1, 2024

Choose a reason for hiding this comment

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

We also have isVisible exposed on ElementReader. So I think it's good to keep them separate.

Although, related to your comment here: #8381 (comment), the devil's advocate is that ideally for the customer's use case we'd expose a property that captures whether or not the element would be fully captured by our Screenshot Brick.

We just happen to know there's no funny business going on the site they need to screenshot, so the method as-is would be sufficient.

Perhaps there's a better name we could use the method/output property? Although, from the Google/SO Results, this is what most developers seem to call it. (Although a good proportion of them seem to use it to mean the element is at least partially in the viewport)

Some other name options for brainstorming:

  • isFullyWithinViewport
  • isPositionedWithinViewport
  • isFullyPositionedWithinViewport

Although "position" might be confusing w.r.t. CSS position properties

Copy link
Collaborator

@fungairino fungairino May 1, 2024

Choose a reason for hiding this comment

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

We just happen to know there's no funny business going on the site they need to screenshot

Maybe I'm missing the context, but is this for a specific customer?

I think it's fine to leave the methodName and functionality as-is, but I would recommend updating the jsdoc to be more comprehensive on the behavior and limitations of this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I'm missing the context, but is this for a specific customer?

Yes. To see that you can look for the "customer" label and user story in the issue: #8380. Adding the customer name epic now

I think it's fine to leave the methodName and functionality as-is, but I would recommend updating the jsdoc to be more comprehensive on the behavior and limitations of this function.

👍

Copy link

github-actions bot commented May 1, 2024

No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack.

Do not edit this comment manually.

@twschiller twschiller enabled auto-merge (squash) May 1, 2024 11:50
@twschiller twschiller changed the title #8380: add isInViewport to element reader #8380: add isInViewport property to element reader May 1, 2024
@twschiller twschiller added the enhancement New feature or request label May 1, 2024
@twschiller twschiller merged commit 47e4885 into main May 1, 2024
30 checks passed
@twschiller twschiller deleted the feature/8380-in-viewport branch May 1, 2024 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
brick customer Required for a customer projct enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add isInViewport property to element reader
2 participants