JavaScript Navigator deprecatedReplaceInURN() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Method

Definition

navigator.deprecatedReplaceInURN(urnOrConfig, replacements) substitutes placeholders inside the browser-mapped URL for an opaque URN or FencedFrameConfig (MDN). JavaScript never sees that URL.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call navigator.deprecatedReplaceInURN. Start with this line.

JavaScript
navigator.deprecatedReplaceInURN(urnOrConfig, replacements)
CallWhat it does
navigator.deprecatedReplaceInURN(urnOrConfig, replacements)Primary signature.
navigator.deprecatedReplaceInURN(...)Call with the arguments your case needs.

Built into the browser. Call deprecatedReplaceInURN(...) on a Navigator — no import required.

Library declarations
JavaScript
navigator.deprecatedReplaceInURN(urnOrConfig, replacements)

Parameters

ParameterDescription
UrnOrConfigRequired. Opaque URN or FencedFrameConfig
replacementsRequired. Object of placeholder → string
Key formatRequired. ${string} or %%string%% only

Return Value

Return ValueDescription
*Promise → undefined

JavaScript Examples

Example 1 — Feature Detection

Check whether the temporary Fenced Frame helper exists.

JavaScript
const lines = [
  "deprecatedReplaceInURN: " +
    (typeof navigator.deprecatedReplaceInURN === "function"
      ? "available"
      : "missing"),
  "isSecureContext: " + window.isSecureContext
];
console.log(lines.join("\n"));
Try It Yourself

How It Works

  1. Test with typeof. Avoids calling a missing method.
  2. Expect missing. Most browsers and everyday sites never expose this API.
  3. Note secure context. Privacy Sandbox APIs typically need HTTPS.
  4. Do not build on it. Even when present, MDN marks it for removal.

Example 2 — Validate Placeholder Keys

Only ${string} and %%string%% keys are allowed (MDN).

JavaScript
function isAllowedReplacementKey(key) {
  return /^\$\{.+\}$/.test(key) || /^%%.+%%$/.test(key);
}

const samples = ["${foo}", "%%baz%%", "foo", "{bar}"];
console.log(
  samples
    .map((k) => k + ": " + (isAllowedReplacementKey(k) ? "allowed" : "invalid"))
    .join("\n")
);
Try It Yourself

How It Works

  1. Match two formats. Dollar-brace ${…} or double-percent %%…%%.
  2. Reject free-form keys. foo and {bar} are not allowed.
  3. Why it matters. Invalid formats throw TypeError on the real API.
  4. Validate early. Check keys before calling the browser method.

Example 3 — MDN Substitution Shape

Show the call shape MDN documents (needs a real URN in a supporting environment).

JavaScript
async function tryMdnStyleReplace(exampleURN) {
  if (typeof navigator.deprecatedReplaceInURN !== "function") {
    return "API missing — cannot substitute fenced URN URLs here";
  }
  if (!exampleURN) {
    return "No URN / FencedFrameConfig — obtain one from an auction API first";
  }
  await navigator.deprecatedReplaceInURN(exampleURN, {
    "${foo}": "1",
    "${bar}": "2",
    "%%baz%%": "3"
  });
  return "Substitution requested (internal URL updated by the browser)";
}

tryMdnStyleReplace(null).then(console.log);
Try It Yourself

How It Works

  1. Detect the method. Exit early when the API is gone (common).
  2. Require a real URN. Without auction output, there is nothing to map.
  3. Pass allowed keys. MDN’s example replaces ${foo}, ${bar}, %%baz%%.
  4. Await the Promise. Success means the browser updated its internal mapping.

Example 4 — Catch Invalid Replacement Keys

Block free-form keys before calling the API.

JavaScript
async function replaceWithGuardedKeys(urn, replacements) {
  if (typeof navigator.deprecatedReplaceInURN !== "function") {
    return "API missing";
  }
  const bad = Object.keys(replacements).filter(
    (k) => !(/^\$\{.+\}$/.test(k) || /^%%.+%%$/.test(k))
  );
  if (bad.length) {
    return "Blocked invalid keys: " + bad.join(", ");
  }
  try {
    await navigator.deprecatedReplaceInURN(urn, replacements);
    return "OK";
  } catch (err) {
    return "Error: " + err.name;
  }
}

replaceWithGuardedKeys("urn:example", { foo: "1", "${bar}": "2" }).then(console.log);
Try It Yourself

How It Works

  1. List the keys. Scan every property name in replacements.
  2. Filter invalid ones. Anything not ${…} / %%…%% is blocked.
  3. Return a clear message. Better than a raw TypeError in app logs.
  4. Still try/catch. Bad URN / config can also throw.

Example 5 — Beginner Production Guard

Remind teams this is a temporary ad-tech bridge, not a general URL API.

JavaScript
function shouldUseDeprecatedReplaceInURN(options) {
  if (!options || !options.migratingFencedFrameCreatives) {
    return "Skip — not migrating fenced-frame ad creatives";
  }
  if (typeof navigator.deprecatedReplaceInURN !== "function") {
    return "Skip — API unavailable in this browser";
  }
  return "Legacy only — prefer not to adopt; API is deprecated";
}

console.log(shouldUseDeprecatedReplaceInURN({ migratingFencedFrameCreatives: false }));
console.log(shouldUseDeprecatedReplaceInURN({ migratingFencedFrameCreatives: true }));
Try It Yourself

How It Works

  1. Default to skip. Normal apps should never enter this path.
  2. Require an explicit migration flag. Avoid accidental calls.
  3. Detect the API. Missing means you cannot (and need not) use it.
  4. Prefer exit. Even when available, treat it as legacy — not a feature to build on.

Browser Support

navigator.deprecatedReplaceInURN() is Deprecated (to be removed), Experimental, and not Baseline. Limited Chromium exposure (roughly Chrome / Edge 128+) for Privacy Sandbox / fenced-frame work; Firefox and Safari do not support it. Do not depend on it.

✓ Deprecated · Experimental · Not Baseline

Navigator.deprecatedReplaceInURN()

Temporary URN / FencedFrameConfig placeholder substitution — pending removal.

Legacy Do not adopt
Google Chrome ~128+ (limited · pending removal)
Limited
Microsoft Edge ~128+ (limited · pending removal)
Limited
Apple Safari No support
Unavailable
Opera Follow Chromium where present
Limited
Mozilla Firefox No support
Unavailable
Internet Explorer No support
Unavailable
deprecatedReplaceInURN() Legacy

Bottom line: Recognize the API for literacy. Feature-detect if you must maintain old ad-tech code, but plan to remove it — MDN marks it for removal.

Frequently Asked Questions

It substitutes specified placeholder strings inside the browser-mapped internal URL for an opaque URN or FencedFrameConfig — without exposing that URL to JavaScript.
Both. MDN marks it Deprecated (to be removed) and Experimental. Chrome is withdrawing related Privacy Sandbox / fenced-frame APIs. Do not use it in new code; everyday apps never need it.
Mainly ad tech providers who needed temporary creative URL substitution inside fenced frames / Protected Audience. Normal web apps should skip it.
Replacement keys must use ${string} or %%string%%. Other formats throw TypeError. If a correctly formatted key is missing from the URL, the Promise still fulfills and that key is skipped.
A Promise that fulfills with undefined when the call succeeds.
No. The content URL is mapped internally by the browser and is not accessible via JavaScript — that is why substitution happens through this API instead of editing a public URL string.

Next: getAutoplayPolicy()

Learn how browsers report autoplay policy for media elements.

getAutoplayPolicy() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful