{"id":11153,"library":"js-library-detector","title":"JavaScript Library Detector","description":"js-library-detector is an npm package that provides programmatic access to the detection logic used by the 'Library Detector for Chrome' browser extension. It identifies various JavaScript frameworks and libraries in use on a given webpage by inspecting the `window` object and other global properties. The current stable version is 6.7.0, and the project demonstrates an active release cadence with frequent updates adding new library detections (e.g., WordPress, Gatsby, Shopify, Wix, Magento) and refining existing ones. Its key differentiator is its comprehensive list of supported libraries and its origin as a widely used browser extension, providing robust, battle-tested detection capabilities in a headless or server-side rendering context via tools like JSDOM or Puppeteer.","status":"active","version":"6.7.0","language":"javascript","source_language":"en","source_url":"https://github.com/johnmichel/Library-Detector-for-Chrome","tags":["javascript","libraries","googlechrome"],"install":[{"cmd":"npm install js-library-detector","lang":"bash","label":"npm"},{"cmd":"yarn add js-library-detector","lang":"bash","label":"yarn"},{"cmd":"pnpm add js-library-detector","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The 'detect' function is a named export. The package's `main` entry uses CommonJS `module.exports = { detect: ... }`.","wrong":"import detector from 'js-library-detector';","symbol":"detect","correct":"import { detect } from 'js-library-detector';"},{"note":"When using CommonJS, it's common to destructure the `detect` function directly from the exported object.","wrong":"const detector = require('js-library-detector');\ndetector();","symbol":"detect (CommonJS)","correct":"const { detect } = require('js-library-detector');"},{"note":"The package also exports a 'libraries' object containing metadata about all detectable libraries.","symbol":"libraries (CommonJS)","correct":"const { libraries } = require('js-library-detector');"}],"quickstart":{"code":"import { JSDOM } from 'jsdom';\nimport { detect } from 'js-library-detector';\n\nasync function detectLibrariesOnPage(url) {\n  try {\n    const response = await fetch(url);\n    const html = await response.text();\n\n    const dom = new JSDOM(html, {\n      url: url,\n      resources: 'usable',\n      runScripts: 'dangerously',\n      beforeParse(window) {\n        // Mock common browser APIs if necessary for detections that rely on them\n        window.Element.prototype.getBoundingClientRect = () => ({\n          width: 10, height: 10, top: 0, left: 0, bottom: 0, right: 0,\n        });\n      }\n    });\n\n    // Wait for the DOM and scripts to load/execute\n    // This is crucial as many libraries are initialized after page load\n    await new Promise(resolve => {\n      dom.window.addEventListener('load', resolve);\n      // Fallback in case 'load' doesn't fire for some reason (e.g., no scripts)\n      setTimeout(resolve, 5000); // Wait up to 5 seconds for scripts\n    });\n\n    // Perform detection using the JSDOM window object\n    // The detect function expects a window object as 'this' context\n    const detected = detect.call(dom.window, { html: dom.window.document.documentElement.outerHTML });\n\n    const detectedNames = Object.keys(detected).filter(lib => detected[lib].found);\n    console.log(`Detected libraries on ${url}:`);\n    if (detectedNames.length > 0) {\n      detectedNames.forEach(name => {\n        console.log(`- ${name} (version: ${detected[name].version || 'N/A'})`);\n      });\n    } else {\n      console.log('No known libraries detected.');\n    }\n  } catch (error) {\n    console.error(`Error detecting libraries on ${url}:`, error);\n  }\n}\n\n// Example usage: detect libraries on a public website (e.g., Google)\n// Note: This requires 'jsdom' and 'node-fetch' to be installed.\n// `npm install jsdom node-fetch`\ndetectLibrariesOnPage('https://www.google.com/');\n","lang":"javascript","description":"This quickstart demonstrates how to use js-library-detector in a Node.js environment by simulating a browser window with JSDOM, loading HTML content, and then executing the detection logic to identify JavaScript libraries present on the page."},"warnings":[{"fix":"Update your detection logic to not expect 'Create React App' to be reported. Consider alternative, more robust methods if this specific detection is critical for your use case.","message":"Detection for 'Create React App' was removed due to conflicts and breaking certain login flows in v6.0.0. If your application relies on detecting CRA, this functionality is no longer available.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"When using `js-library-detector` in Node.js, ensure you're passing a `window` object from a JSDOM instance or a Puppeteer page context to the `detect` function, typically by using `detect.call(window, options)`.","message":"The `detect` function must be called with a browser-like `window` object as its `this` context for accurate results. Running it directly in a Node.js environment without a simulated DOM (like JSDOM) or headless browser (like Puppeteer) will yield incorrect or no detections.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are either running the detection in a browser environment, or providing a simulated browser `window` object when using it in Node.js, e.g., `detect.call(dom.window, options);`.","cause":"The `detect` function was called without a valid `window` object in its execution context, likely in a Node.js environment without JSDOM or similar setup.","error":"TypeError: Cannot read properties of undefined (reading 'window')"},{"fix":"Set up a JSDOM instance in your Node.js environment and pass its `window` object to the `detect` function's `this` context, or execute the code within a browser or headless browser context.","cause":"Similar to the `window` error, this occurs when the detection logic attempts to access `document` (which resides on `window`) in an environment where it's not present.","error":"ReferenceError: document is not defined"},{"fix":"When using JSDOM or Puppeteer, ensure you wait sufficiently for the page's scripts to execute and for all dynamic content to render before invoking the `detect` function. In JSDOM, use `dom.window.addEventListener('load', ...)` or a `setTimeout` with a reasonable delay after `runScripts: 'dangerously'` is enabled. In Puppeteer, use `page.goto(url, { waitUntil: 'networkidle0' })` or `page.waitForSelector()`.","cause":"This often happens when running detection on dynamically loaded content or pages that execute complex JavaScript after initial DOM load. The detector might run before all scripts have initialized the libraries.","error":"Detected libraries are inconsistent or incomplete compared to actual page content."}],"ecosystem":"npm"}