MCPcopy Index your code
hub / github.com/ampproject/amphtml / replaceUrl

Method replaceUrl

src/service/viewer-impl.js:866–892  ·  view source on GitHub ↗

@override

(newUrl)

Source from the content-addressed store, hash-verified

864
865 /** @override */
866 replaceUrl(newUrl) {
867 if (
868 !newUrl ||
869 !this.ampdoc.isSingleDoc() ||
870 !this.win.history.replaceState
871 ) {
872 return;
873 }
874
875 try {
876 // The origin and source origin must match.
877 const url = parseUrlDeprecated(this.win.location.href);
878 const replaceUrl = parseUrlDeprecated(
879 removeFragment(newUrl) + this.win.location.hash
880 );
881 if (
882 url.origin == replaceUrl.origin &&
883 getSourceOrigin(url) == getSourceOrigin(replaceUrl)
884 ) {
885 this.win.history.replaceState({}, '', replaceUrl.href);
886 this.win.location['originalHref'] = url.href;
887 dev().fine(TAG_, 'replace url:' + replaceUrl.href);
888 }
889 } catch (e) {
890 dev().error(TAG_, 'replaceUrl failed', e);
891 }
892 }
893
894 /**
895 * Defense in-depth against viewer communication issues: Will make the

Callers 2

test-viewer.jsFile · 0.45
handleReplaceUrlFunction · 0.45

Calls 8

parseUrlDeprecatedFunction · 0.90
removeFragmentFunction · 0.90
getSourceOriginFunction · 0.90
devFunction · 0.90
replaceStateMethod · 0.80
fineMethod · 0.80
isSingleDocMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected