
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
This is a simple utility that takes an element and generates a corresponding Xpath for it.
This is a simple utility that takes an element and generates a corresponding Xpath for it.
It contains a single method getXpath which returns an object containing 3 values:
export interface ElementInfo {
xpath: string;
customPath: string;
elementData: {};
}
npm install xpath-util
This is the entire xpath from the element to the root element on the page. Elements will be tagged with a class or* and id if present.
* For now elements will only contain a class or the id if present. It will not contain both. The precendence is to use the id if available.
As xpaths can at times be difficult to parse you have the opportunity to generate a much smaller and high fidelty path using two data- attributes: data-analytics and data-analytics-type. By tagging your element
The usage of these looks a little as follows:
<div
data-analytics="ec2"
data-analytics-type="service"
>
This segment will produce a custom path of /service(ec2)
Instead of having to parse data out of the analytic path we also provide an object containing all the data from custom path. For the above example it would look as follows:
{"service": "ec2"}
Given the following snippet of HTML:
<div id="another-better-id">
<div
id="some-unique-id"
data-analytics="otherParent"
data-analytics-type="serviceSubSection"
>
<div
class="ASKLJHASDLKJH"
style="background: #eee; padding: 10px"
data-analytics="introParagraph"
>
<p>
This is a sibling paragraph
</p>
<p>
This paragraph
contains a lot of spaces
in the source code,
but the browser
ignores it.
</p>
</div>
</div>
</div>
The following you can execute the following code:
const firstParagraph = (document.querySelector("#another-better-id p") as HTMLElement);
const firstParagraphElementInfo = getXpath(firstParagraph)
The variable firstParagraphElementInfo will equal the following:
"customPath": "/serviceSubSection(otherParent)/tag(introParagraph)",
"elementData": {
"serviceSubSection": "otherParent",
"tag": "introParagraph",
},
"xpath": "/html/body/div/div[@id=\\"another-better-id\\"]/div[@id=\\"some-unique-id\\"]/div[@class=\\"ASKLJHASDLKJH\\"]/p",
See CONTRIBUTING for more information.
This project is licensed under the Apache-2.0 License.
FAQs
This is a simple utility that takes an element and generates a corresponding Xpath for it.
We found that xpath-util 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
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.