JavaScript Navigator deprecatedReplaceInURN() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Experimental

What You’ll Learn

navigator.deprecatedReplaceInURN() substitutes placeholders inside a browser-mapped fenced-frame URL for an opaque URN or FencedFrameConfig. Learn the purpose, allowed ${string} / %%string%% key formats, MDN examples, five labs, and why everyday sites can skip this API.

01

Kind

Method

02

Returns

Promise<undefined>

03

Status

Experimental

04

Audience

Ad tech / fenced frames

05

API family

Fenced Frame API

06

Placeholders

${name} / %%name%%

Introduction

Fenced frames load privacy-sensitive content (often ads) without letting the embedder read the destination URL. A source such as Protected Audience runAdAuction() can return an opaque URN or a FencedFrameConfig, which you assign to a <fencedframe>. The real URL stays inside the browser.

Older ad systems still inject runtime values into creative URLs (campaign ids, sizes, and so on). deprecatedReplaceInURN() is a temporary bridge: it replaces allowed placeholders in that hidden URL so creatives keep working while teams migrate.

💡
Beginner takeaway

You will almost never call this in a normal blog, shop, or dashboard. Learn the shape so you can recognize it in Privacy Sandbox / ad docs — then move on unless you are migrating fenced-frame creatives.

Understanding the deprecatedReplaceInURN() Method

  • Input 1 — a FencedFrameConfig or opaque URN from an auction / similar source.
  • Input 2 — a replacements object whose keys are placeholders and values are substitute strings.
  • Allowed keys${string} or %%string%% only.
  • Missing placeholders — correctly formatted keys that are not in the URL are skipped; the Promise still fulfills.
  • Invalid keys / URN — can throw TypeError.
  • Temporary — named for migration; plan to leave it behind in new designs.

📝 Syntax

General form of the method:

JavaScript
navigator.deprecatedReplaceInURN(UrnOrConfig, replacements)

Parameters

  • UrnOrConfig — a FencedFrameConfig or opaque URN whose internal URL should be updated.
  • replacements — object of placeholder → replacement string pairs.

Return value

  • A Promise that fulfills with undefined.

Common patterns

JavaScript
// MDN-style flow (requires a real auction URN / config)
const exampleURN = await navigator.runAdAuction({
  ...auctionConfig,
  resolveToConfig: false
});

await navigator.deprecatedReplaceInURN(exampleURN, {
  "${foo}": "1",
  "${bar}": "2",
  "%%baz%%": "3"
});

// Before (internal URL, not readable from JS):
// https://example.com/a=${foo}&b=${bar}&c=%%baz%%
// After:
// https://example.com/a=1&b=2&c=3

⚡ Quick Reference

GoalCode
Feature detecttypeof navigator.deprecatedReplaceInURN === "function"
Replace placeholdersawait navigator.deprecatedReplaceInURN(urn, map)
Allowed key styles${name} or %%name%%
Get opaque URN (ad flow)runAdAuction({ resolveToConfig: false })
StatusExperimental · temporary migration helper

🔍 At a Glance

Four facts to remember about navigator.deprecatedReplaceInURN().

Returns
Promise

Fulfills undefined

Status
Experimental

Not Baseline

Keys
${} / %%

Strict formats

Audience
Ad tech

Fenced frames

📋 Editing a Normal URL vs Fenced URN Substitution

Normal page URLFenced URN / config
Can JS read the URL?Yes (e.g. location.href)No — mapped internally
How to substitute?Build a new string yourselfdeprecatedReplaceInURN()
Typical useEveryday navigation / APIsPrivacy-preserving ads / creatives
Beginner appsCommonUsually never needed

Examples Gallery

Examples follow MDN patterns. Prefer Try It Yourself — a real auction URN / FencedFrameConfig is rare outside Privacy Sandbox demos, so labs focus on detection, placeholder rules, and safe calling patterns.

📚 Getting Started

Detect the method and learn the only allowed placeholder formats.

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

Missing is the normal result for most browsers and everyday sites.

Example 2 — Validate Placeholder Keys

Only ${string} and %%string%% keys are allowed by 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

Invalid key formats cause TypeError when passed to the real API.

📈 Practical Patterns

Sketch the MDN call, handle bad keys, and guard beginners away from production use.

Example 3 — MDN Substitution Shape

Show the call shape MDN documents (needs a real URN in a Privacy Sandbox 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 runAdAuction (or similar) 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

MDN’s before/after example turns …a=${foo}&b=${bar}&c=%%baz%% into …a=1&b=2&c=3 inside the browser mapping.

Example 4 — Catch Invalid Replacement Keys

Demonstrate why key validation matters 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

Rejecting bad keys early avoids a TypeError from the browser.

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 "OK to feature-detect and call for temporary migration only";
}

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

How It Works

Gate the call behind an explicit migration flag so beginners do not copy it into unrelated apps.

🚀 Common Use Cases

  • Ad creative migration — keep placeholder substitution while moving to fenced frames.
  • Protected Audience flows — after runAdAuction returns an opaque URN.
  • FencedFrameConfig setups — substitute values before assigning config.
  • Runtime creative params — inject size / slot / campaign tokens without exposing the URL.
  • Learning Privacy Sandbox — recognize the API when reading advanced docs.

🧠 How navigator.deprecatedReplaceInURN() Works

1

Obtain a URN or config

Often from runAdAuction with resolveToConfig: false (or a config).

Auction
2

Build allowed replacements

Keys must be ${name} or %%name%%.

Map
3

Await the method

The browser updates the internal mapped URL.

Replace
4

Load the fenced frame

Assign the URN / config; the creative sees substituted values without leaking the URL to the embedder.

📝 Notes

  • Experimental & Limited availability — not Baseline; feature-detect always.
  • Not MDN-Deprecated or Non-standard — Experimental banner only (name signals temporary migration).
  • Niche Privacy Sandbox / ad-tech API — skip for typical beginner projects.
  • Returns a Promise; invalid keys or URN/config can throw TypeError.
  • Related: getAutoplayPolicy(), canShare(), xr, Window.

Limited / Experimental Support

navigator.deprecatedReplaceInURN() belongs to the experimental Fenced Frame API and is not Baseline. Support is limited to Privacy Sandbox / fenced-frame capable browsers. Always feature-detect and treat the method as a temporary migration aid for ad creatives.

Experimental · Not Baseline

Navigator.deprecatedReplaceInURN()

Temporary helper — substitute ${} / %% placeholders in a mapped fenced-frame URL.

Limited Experimental
Google Chrome Privacy Sandbox / Fenced Frame capable builds
Limited
Microsoft Edge Follow Chromium Fenced Frame support
Limited
Opera Follow Chromium where available
Limited
Mozilla Firefox Typically unavailable — feature-detect
Unavailable
Apple Safari Typically unavailable — feature-detect
Unavailable
Internet Explorer No Fenced Frame / this method
Unavailable
deprecatedReplaceInURN() Limited

Bottom line: Detect the method, validate placeholder keys, use it only for fenced-frame creative migration, and plan to remove the temporary bridge.

Conclusion

navigator.deprecatedReplaceInURN() is an experimental, temporary way to substitute ${name} / %%name%% placeholders inside a browser-mapped fenced-frame URL. Detect it, validate keys, use it only for Privacy Sandbox creative migration, and keep it out of everyday app code.

Continue with getAutoplayPolicy(), canShare(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect before calling
  • Use only ${name} / %%name%% replacement keys
  • Treat it as a temporary migration helper
  • Handle TypeError for bad URN/config or keys
  • Prefer modern Privacy Sandbox patterns for new work

❌ Don’t

  • Use this in ordinary beginner web apps
  • Expect to read the internal fenced URL from JavaScript
  • Pass free-form keys like "foo"
  • Assume Baseline / universal support
  • Build long-term architecture on this temporary bridge

Key Takeaways

Knowledge Unlocked

Five things to remember about deprecatedReplaceInURN()

Experimental fenced-frame URL substitution for ad-tech migration.

5
Core concepts
02

Status

Experimental

Limited
📄 03

Keys

${} or %%

Formats
🔒 04

URL hidden

Browser-mapped

Privacy
🎯 05

Scope

Ad tech bridge

Temporary

❓ 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.
MDN marks it Experimental and Limited availability (not Baseline). The word "deprecated" in the method name signals a temporary migration helper for ad tech — it is not listed as a Deprecated MDN status badge. Prefer Privacy Sandbox / Fenced Frame patterns designed for new work.
Mainly ad tech providers migrating older creative URL substitution into fenced frames / Protected Audience. Everyday web apps usually never need it.
Replacement keys must use ${string} or %%string%%. Other key 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 string editing a public URL.
Did you know?

If a placeholder key is correctly formatted but not present in the internal URL, the Promise still fulfills — the browser simply skips that substitution instead of failing.

Explore getAutoplayPolicy() Next

Ask the browser how media and Web Audio may autoplay.

getAutoplayPolicy() →

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.

8 people found this page helpful