
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
@nichoth/dom
Advanced tools
Helpers for working with the DOM, useful for tests.
npm i -D @nichoth/dom
import { dom } from '@nichoth/dom'
// or import individual functions
import { waitFor } from '@nichoth/dom'
const dom = require('@nichoth/dom').dom
dom.qs points to document.querySelector
dom.qsa is equal to document.querySelectorAll
Look for a DOM element by slector. Default timeout is 5 seconds. Throws if the element is not found.
function waitFor (args:{
selector?:string,
visible?:boolean,
timeout?:number
}|string, lambda?:() => Element|null):Promise<Element>
import { waitFor } from '@nichoth/dom'
const foundElement = await waitFor({
selector: 'p'
})
// or pass in a string to use as a query selector
const el = await waitFor('#my-element')
Look for an element containing the given text, or that matches a given regex. Return the element if found. Default timeout is 5 seconds. Throws if the element is not found.
function waitForText (args:{
text?:string,
timeout?:number,
element:Element,
multipleTags?:boolean,
regex?:RegExp
}):Promise<Element>
import { waitForText } from '@nichoth/dom'
const el = await waitForText({
element: document.body,
regex: /bar/
})
Pass in a parent element and timeout.
const found = await waitForText({
element: dom.qs('#test-two'),
multipleTags: true,
text: 'bbb',
timeout: 10000 // 10 seconds
})
Dispatch a click event from the given element.
import { dom } from '@nichoth/dom'
// or import { click } from '@nichoth/dom'
dom.click(dom.qs('#my-element'))
Dispatch an event from an element.
function event (args:{
event:string|Event;
element?:HTMLElement|Element|typeof window
}):void
import { dom } from '@nichoth/dom'
dom.event({ event: 'hello', element: dom.qs('#example') })
Wait for the given milliseconds.
async function sleep (ms:number):Promise<void>
import { sleep } from '@nichoth/dom'
await sleep(3000) // wait 3 seconds
Thanks Jake Verbaten for writing this originally.
FAQs
Helpers for working with the DOM
We found that @nichoth/dom 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 is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.