Replacing glob-all with fs.promises.glob in Node.jsArticle contains
  1. The glob-all way of using
  2. Replace glob-all with fs.promises.glob in Node.js at least 22.2
  3. Mapping old way to new way
  4. Quick conversion rule
  5. Error handling
  6. Benefits of using fs.promises.glob
  7. Example use case
  8. Conclusion
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”
Chrome DevTools XPath safety - escape the JavaScript literal not the XPathArticle contains
  1. When a simple XPath field becomes Remote Code Execution (RCE)
  2. Why document.evaluate itself is innocent
  3. The JavaScript meta-character trap
  4. Sanitizing XPath
  5. Integration recipes
  6. Solutions that fail security review
  7. Short security checklist
  8. Final words
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”
JavaScript and wait until DOM element existsArticle contains
  1. Introduction
  2. How to wait until a DOM element exists before executing a JavaScript function?
  3. Solution and implementation
  4. Workable example
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”
Escape HTML string tags in JavaScriptArticle contains
  1. Why escape HTML?
  2. What happens when HTML is not escaped?
  3. How does escaping HTML prevent XSS attacks?
  4. When to escape HTML?
  5. Best practices for secure HTML escaping
    1. Escape on output, not on input
    2. Use a trusted escaping mechanism
    3. Avoid manual replacement
    4. Test your escaping mechanism
    5. Consider Content Security Policy (CSP)
  6. How to escape an HTML string in JavaScript?
    1. Character replacement
    2. Tagged template literal function
  7. When to use the escapeHtml template literal function
  8. Comparison of the provided code examples
  9. In summary
Implement "Please wait" message while iframe is loading using JavaScriptArticle contains
  1. Easy steps to implement a Please Wait message
  2. The code usage example
  3. Understanding the code
  4. Workable example
  5. Tips for enhancements and important considerations
  6. Conclusion
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”
Explore focusable, clickable, tabbable or active statesArticle contains
  1. What is the difference between an interactive element that can receive focus, be clicked, be active, or be tabbable?
  2. Determine if an element is clickable
  3. Determine if an element is focusable
    1. Determining if an element is a type of focusable element
    2. Determining if the element can receive focus right now
  4. Determine which element is active now
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”
Fixing missing tooltips for invalid required form controlsArticle contains
  1. Solution implementation
  2. Workable example
Using async and await with browser.runtime.onMessage in cross-browser extensionsArticle contains
  1. Understanding message passing
  2. Key points for using async/await
  3. Example implementation
  4. Conclusion
JavaScript Clipboard API with fallbackArticle contains
  1. Using the Clipboard API
  2. Unsanitized HTML in the Async Clipboard API
  3. Limitations
  4. JavaScript Clipboard API example
Preventing multiple HTTP requests to the same endpointArticle contains
  1. Why preventing multiple requests is important
  2. Preventing multiple requests with caching, TypeScript version
    1. Example use case for TypeScript
  3. Preventing multiple requests with caching, Angular version
    1. Example of how to include interceptor in Angular
    2. Execution flow
    3. Benefits
    4. Potential issues