
Security News
Software Engineering Daily Podcast: Feross on AI, Open Source, and Supply Chain Risk
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.
This library was built on faulty assumptions. You are better off calling getBoundingClientRect() inside of requestAnimationFrame(), which has essentially the same effect while avoiding the cost of creating an IntersectionObserver, as this benchmark demonstrates.
Original documentation follows.
Asynchronous version of getBoundingClientRect(), built on top of IntersectionObserver.
It works the same as getBoundingClientRect(), except you don't need to worry about layout thrashing or forcing layouts/reflows, because this function asynchronously waits for the next browser layout pass instead of synchronously forcing layout.
This library also works around some browser bugs.
npm install async-rect
import asyncGetBoundingClientRect from 'async-rect'
(async () => {
let element = document.querySelector('#myElement')
let rect = await asyncGetBoundingClientRect(element)
console.log(rect)
// { width: 100, height: 50, left: 0, top: 0, bottom: 50, right: 100 }
})()
Or use as a script tag:
<script src="https://unpkg.com/async-rect/dist/async-rect.min.js"></script>
<script>
asyncGetBoundingClientRect(element).then(/* ... */)
</script>
This library requires both IntersectionObserver and Promises. If you need to support browsers without those features, please use the polyfills:
This library is written in ES5, so it will work in older browsers assuming you have the polyfills.
This library creates a new IntersectionObserver object and then disconnect()s it when it's done. As an optimization, you may want to re-use the same IntersectionObserver object and manage its lifecycle yourself. (Note though that re-using the same IntersectionObserver object will not work if you want to invoke the function twice on the same element.) You may also want to do this if you are interested in using a root element other than the viewport, or if you want to know the rootBounds as well, or if you have some other particular use case.
In those cases, the library is quite small, so feel free to fork as you see fit! đ
npm run build
npm test
FAQs
DEPRECATED - do not use
The npm package async-rect receives a total of 2 weekly downloads. As such, async-rect popularity was classified as not popular.
We found that async-rect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.

Security News
Rustâs crates.io team is advancing an RFC to add a Security tab that surfaces RustSec vulnerability and unsoundness advisories directly on crate pages.