{"id":26572,"library":"url-api-polyfill","title":"URL API Polyfill","description":"A lightweight polyfill for the URL and URLSearchParams APIs in environments where they are not natively supported, such as older browsers (IE, legacy Edge) or Node.js versions before v10. Current stable version is 1.1.0. No breaking changes since first release. Simpler than `whatwg-url` — focused solely on browser compatibility without extra parsing logic.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/michael-iglesias/url-api-polyfill","tags":["javascript","polyfill"],"install":[{"cmd":"npm install url-api-polyfill","lang":"bash","label":"npm"},{"cmd":"yarn add url-api-polyfill","lang":"bash","label":"yarn"},{"cmd":"pnpm add url-api-polyfill","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This polyfill mutates the global scope. No named import needed.","wrong":"import { URL } from 'url-api-polyfill'","symbol":"URL","correct":"import 'url-api-polyfill';\n// URL is then globally available"},{"note":"Import the module for the side effect; both classes become global.","wrong":"const { URLSearchParams } = require('url-api-polyfill')","symbol":"URLSearchParams","correct":"import 'url-api-polyfill';\n// URLSearchParams is globally available"},{"note":"CJS import does not export anything; it only patches globals.","wrong":"const url = require('url-api-polyfill');\n// url is an empty object","symbol":"require (CJS)","correct":"require('url-api-polyfill');\n// After require, URL and URLSearchParams are global"}],"quickstart":{"code":"// Install: npm install url-api-polyfill\nimport 'url-api-polyfill';\n\nconst url = new URL('https://user:pass@example.com:8080/path?query=1#hash');\nconsole.log(url.protocol);   // 'https:'\nconsole.log(url.hostname);   // 'example.com'\nconsole.log(url.port);       // '8080'\nconsole.log(url.pathname);   // '/path'\nconsole.log(url.search);     // '?query=1'\nconsole.log(url.hash);       // '#hash'\nconsole.log(url.username);   // 'user'\nconsole.log(url.password);   // 'pass'\n\nconst params = new URLSearchParams('key1=value1&key2=value2');\nconsole.log(params.get('key1')); // 'value1'","lang":"javascript","description":"Demonstrates side-effect import and usage of global URL and URLSearchParams."},"warnings":[{"fix":"Use `import 'url-api-polyfill'` (no named imports). After import, URL and URLSearchParams are globally available.","message":"Importing the module does not return any exports — it only patches globals. Do not try to destructure imports.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Test your specific use cases. Consider using `whatwg-url` or native APIs in modern environments.","message":"The polyfill may not perfectly replicate native URL behavior in all edge cases (e.g., IDN support, percent-encoding quirks).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Remove the polyfill and use native URL/URLSearchParams. Polyfill conditionally or use a more up-to-date library like `whatwg-url`.","message":"This package is rarely updated; native support is now widespread. Consider dropping the polyfill if you target modern browsers or Node >=10.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Change to `import 'url-api-polyfill'`.","cause":"Wrong import style: the package only has side effects, no named exports.","error":"import { URL } from 'url-api-polyfill' → 'URL' is not exported from 'url-api-polyfill'"},{"fix":"Ensure the package is installed and imported via `import 'url-api-polyfill'` at the entry point.","cause":"The polyfill was not imported before using URL, or it's not installed.","error":"TypeError: URL is not a constructor"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}