JSC Safe URL Utilities

0.2.4 · active · verified Tue Apr 21

jsc-safe-url is a specialized utility package designed to address a specific behavior in JavaScriptCore (JSC) where query strings and URL fragments are stripped from source URLs when they appear in error stacks. This sanitization can obscure vital debugging information, particularly in environments like React Native that rely on JSC. The package provides three core functions: `toJscSafeUrl` to encode query string data into the URL's path component using a unique `//&` delimiter, `toNormalUrl` to reverse this process and restore the original URL, and `isJscSafeUrl` to check if a URL is currently in the JSC-safe format. This functionality is crucial for implementing proposals like React Native Community RFC0646. The current stable version is 0.2.4. Due to its niche focus on a specific browser engine quirk, its release cadence is typically slow and driven by upstream changes in JSC or React Native's needs, rather than frequent feature additions. Its key differentiator is its precise, targeted solution for this particular JSC URL handling problem.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to convert a standard URL into a JSC-safe format, verify its safety, and then convert it back to its original form, showcasing the package's primary utilities.

import { toJscSafeUrl, toNormalUrl, isJscSafeUrl } from 'jsc-safe-url';

// An example URL that would have its query string stripped by JavaScriptCore
const originalUrl = 'https://my-app.com/bundle.js?platform=ios&dev=true#source-map-id';

console.log(`Original URL: ${originalUrl}`);

// Check if the URL is currently "JSC-safe" (it shouldn't be)
console.log(`Is original URL JSC-safe? ${isJscSafeUrl(originalUrl)}`);
// Expected output: Is original URL JSC-safe? false

// Convert the URL to a JSC-safe format, embedding query params into the path
const jscSafeUrl = toJscSafeUrl(originalUrl);
console.log(`JSC-safe URL: ${jscSafeUrl}`);
// Expected output: JSC-safe URL: https://my-app.com/bundle.js//&platform=ios&dev=true#source-map-id

// Verify the new URL is considered JSC-safe
console.log(`Is JSC-safe URL truly JSC-safe? ${isJscSafeUrl(jscSafeUrl)}`);
// Expected output: Is JSC-safe URL truly JSC-safe? true

// Convert the JSC-safe URL back to its original, normal form
const normalUrl = toNormalUrl(jscSafeUrl);
console.log(`Normal URL after conversion: ${normalUrl}`);
// Expected output: Normal URL after conversion: https://my-app.com/bundle.js?platform=ios&dev=true#source-map-id

// Verify that the restored URL is identical to the original
console.log(`URLs match after round-trip: ${originalUrl === normalUrl}`);
// Expected output: URLs match after round-trip: true

// Example with a URL that has no query string initially
const urlWithoutQuery = 'https://my-app.com/no-query.js';
console.log(`\nIs URL without query JSC-safe? ${isJscSafeUrl(urlWithoutQuery)}`);
// Expected output: Is URL without query JSC-safe? true
console.log(`toJscSafeUrl on no query: ${toJscSafeUrl(urlWithoutQuery)}`);
// Expected output: toJscSafeUrl on no query: https://my-app.com/no-query.js

view raw JSON →