Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
observe-element-in-viewport
Advanced tools
Wrapper around IntersectionObserver to hide away its weirdness and increase ease of usability
In browsers that support the Intersection Observer, this library lets you find out when an element of yours is in viewport. The viewport itself is configurable. It can be the window or any other element in the DOM. Only requirement is that the element who visibility you want to check must be a child of the element you choose as your viewport.
npm install observe-element-in-viewport
target
elementimport { observeElementInViewport } from 'observe-element-in-viewport'
// to use window as viewport, pass this option as null
const viewport = document.querySelector('.viewport')
// element whose visibility we want to track
const target = document.querySelector('.target')
// handler for when target is in viewport
const inHandler = (entry, unobserve, targetEl) => console.log('In viewport')
// handler for when target is NOT in viewport
const outHandler = (entry, unobserve, targetEl) => console.log('Not in viewport')
// the returned function, when called, stops tracking the target element in the
// given viewport
const unobserve = observeElementInViewport(target, inHandler, outHandler, {
// set viewport
viewport,
// decrease viewport top by 100px
// similar to this, modRight, modBottom and modLeft exist
modTop: '-100px'
// threshold tells us when to trigger the handlers.
// a threshold of 90 means, trigger the inHandler when atleast 90%
// of target is visible. It triggers the outHandler when the amount of
// visible portion of the target falls below 90%.
// If this array has more than one value, the lowest threshold is what
// marks the target as having left the viewport
threshold: [90]
})
target
element is in viewportimport { isInViewport } from 'observe-element-in-viewport'
// element whose visibility we want to track
const target = document.querySelector('.target')
// Using window as viewport, it will check the target element's
// visibility and log true or false.
// This function accepts a second parameter which is the same
// as the first parameter to observeElementInViewport fn i.e.,
// the options object.
console.log(await isInViewport(target))
FAQs
Wrapper around IntersectionObserver to hide away its weirdness and increase ease of usability
The npm package observe-element-in-viewport receives a total of 12,392 weekly downloads. As such, observe-element-in-viewport popularity was classified as popular.
We found that observe-element-in-viewport 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.