Node.js logo on the abstract background. Abstract background made by Gerd Altmann from Pixabay.

Replacing glob-all with fs.promises.glob in Node.js

As Node.js continues to get more and more native, built-in features, developers are constantly looking for ways to simplify their code and reduce dependencies on external packages. One such opportunity arises when replacing (or much better alternative to) the glob-all package with the built-in fs.promises.glob function, available in Node.js from version 22.0.0 behind the flag --experimental-glob and became un-flagged in v22.2.0.

Continue reading “Replacing glob-all with fs.promises.glob in Node.js”
A piece of code with the words "Security Alert" on it. Image by Elchinator from Pixabay.

Chrome DevTools XPath safety – escape the JavaScript literal not the XPath

XPath, or XML Path Language, is a query language designed to navigate through elements and attributes in an XML document. The document.evaluate() method in JavaScript allows developers to execute XPath expressions against an XML document, returning nodes or values based on the specified query. While this functionality is powerful, it also poses risks of injection attacks if user input is not properly handled.

Continue reading “Chrome DevTools XPath safety – escape the JavaScript literal not the XPath”
A keyboard placed on a white surface, accompanied by text that includes "JAVASCRIPT Wait for the DOM element."

JavaScript and wait until DOM element exists

To wait for an HTML element to exist in the DOM using JavaScript, we’ll use requestAnimationFrame to periodically check for the element’s existence, and combine it with Promise to achieve this without blocking the main thread.

This approach is performance-friendly because requestAnimationFrame allows the browser to optimize rendering and ensures that the checks occur at the right time in the rendering cycle.

Continue reading “JavaScript and wait until DOM element exists”
Monitor, code on it and the open HTML tag iframe.

Implement “Please wait” message while iframe is loading using JavaScript

When embedding content using iframe (inline frame), users may experience delays while the iframe loads, especially if the content is from a slow server or a third-party site. During this period, users may perceive the application as unresponsive. To mitigate this issue, a Please wait message or an animated loading indicator can be displayed, depending on the design requirements.

Let’s explore the method to implement Please wait message for the iframe using TypeScript, a superset of JavaScript.

Continue reading “Implement “Please wait” message while iframe is loading using JavaScript”
Laptop and cactus on the left side and coffee on the right side. Image by Megan Rexazin Conde from Pixabay.

Explore focusable, clickable, tabbable or active states

Determining whether an element is interactive or not can be crucial for various purposes, such as improving accessibility, enhancing user experience, testing purpose or debugging issues.

An interactive element is one that can receive focus, be clicked, be active, or be tabbable, allowing users to engage with it in some way. Let’s find out how to determine if an element is focusable or active using JavaScript.

Continue reading “Explore focusable, clickable, tabbable or active states”
The example code and the keyboard below it.

How to get the actual (real) background color of an HTML element

In many browsers, when no explicit background color is set for the <html>

or <body> elements, they inherit a transparent background.

However, browsers often render the default background as white for visual consistency, particularly in user interfaces where a clear background is expected. This can lead to confusion when using JavaScript to check computed styles.

Continue reading “How to get the actual (real) background color of an HTML element”