files/en-us/web/api/navigator/deprecatedreplaceinurn/index.md
{{APIRef("Fenced Frame API")}}{{seecompattable}}
The deprecatedReplaceInURN() method of the {{domxref("Navigator")}} interface substitutes specified strings inside the mapped URL corresponding to a given opaque URN or FencedFrameConfig's internal url property.
A FencedFrameConfig or opaque URN is returned from a source such as the Protected Audience API runAdAuction() method, and then set as the value of {{domxref("HTMLFencedFrameElement.config")}}. The content URL associated with the FencedFrameConfig or opaque URN is mapped to it internally by the browser, and can't be accessed via JavaScript.
However, you may wish to substitute parts of that internal URL. This is a common approach for passing runtime data into ad creatives to use in rendering. deprecatedReplaceInURN() has been made available as a temporary measure to enable that substitution for fenced frame URLs, helping ad tech providers to migrate existing implementations across to privacy sandbox APIs.
deprecatedReplaceInURN(UrnOrConfig, replacements)
UrnOrConfig
FencedFrameConfig object or an opaque URN for which you want to substitute parts of the corresponding internal URL.replacements
${string}%%string%%A {{jsxref("Promise")}} that fulfills with {{jsxref("undefined")}}.
TypeError {{domxref("DOMException")}}
UrnOrConfig is not a valid FencedFrameConfig object or opaque URN.The following call could be used to return an opaque URN:
const exampleURN = await navigator.runAdAuction({
...auctionConfig,
resolveToConfig: false,
});
You can then substitute URL subsections using a deprecatedReplaceInURN() call like the following:
await navigator.deprecatedReplaceInURN(exampleURN, {
"${foo}": "1",
"${bar}": "2",
"%%baz%%": "3",
});
If the internal URL associated with the URN is initially:
https://example.com/a=${foo}&b=${bar}&c=%%baz%%
After the substitution it will become:
https://example.com/a=1&b=2&c=3
{{Specifications}}
{{Compat}}