Registry / http-networking / url-api-polyfill

url-api-polyfill

JSON →
library1.1.0jsnpmunverified

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.

npm install url-api-polyfill
INSTALL
IMPORT
SIG · URL-API-POLYFILL
U
url-api-polyfill
http-networkingjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

URL
import 'url-api-polyfill'; // URL is then globally available
import { URL } from 'url-api-polyfill'
This polyfill mutates the global scope. No named import needed.
URLSearchParams
import 'url-api-polyfill'; // URLSearchParams is globally available
const { URLSearchParams } = require('url-api-polyfill')
Import the module for the side effect; both classes become global.
require (CJS)
require('url-api-polyfill'); // After require, URL and URLSearchParams are global
const url = require('url-api-polyfill'); // url is an empty object
CJS import does not export anything; it only patches globals.

Demonstrates side-effect import and usage of global URL and URLSearchParams.

// Install: npm install url-api-polyfill import 'url-api-polyfill'; const url = new URL('https://user:pass@example.com:8080/path?query=1#hash'); console.log(url.protocol); // 'https:' console.log(url.hostname); // 'example.com' console.log(url.port); // '8080' console.log(url.pathname); // '/path' console.log(url.search); // '?query=1' console.log(url.hash); // '#hash' console.log(url.username); // 'user' console.log(url.password); // 'pass' const params = new URLSearchParams('key1=value1&key2=value2'); console.log(params.get('key1')); // 'value1'
Debug
Known issues
gotchaImporting the module does not return any exports — it only patches globals. Do not try to destructure imports.
fix
Use `import 'url-api-polyfill'` (no named imports). After import, URL and URLSearchParams are globally available.
affects: >=1.0.0
gotchaThe polyfill may not perfectly replicate native URL behavior in all edge cases (e.g., IDN support, percent-encoding quirks).
fix
Test your specific use cases. Consider using `whatwg-url` or native APIs in modern environments.
affects: >=1.0.0
deprecatedThis package is rarely updated; native support is now widespread. Consider dropping the polyfill if you target modern browsers or Node >=10.
fix
Remove the polyfill and use native URL/URLSearchParams. Polyfill conditionally or use a more up-to-date library like `whatwg-url`.
affects: >=1.0.0
Errors
Common errors & fixes
import { URL } from 'url-api-polyfill' → 'URL' is not exported from 'url-api-polyfill'
Wrong import style: the package only has side effects, no named exports.
fix
Change to `import 'url-api-polyfill'`.
TypeError: URL is not a constructor
The polyfill was not imported before using URL, or it's not installed.
fix
Ensure the package is installed and imported via `import 'url-api-polyfill'` at the entry point.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
url-api-polyfill — npm install url-api-polyfill · libregistry