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

Method initialize

src/service/url-replacements-impl.js:125–638  ·  view source on GitHub ↗

@override

()

Source from the content-addressed store, hash-verified

123
124 /** @override */
125 initialize() {
126 const {win} = this.ampdoc;
127 const element = this.ampdoc.getHeadNode();
128
129 /** @const {!./viewport/viewport-interface.ViewportInterface} */
130 const viewport = Services.viewportForDoc(this.ampdoc);
131
132 // Greedily cache the geo location if available for synchronous replacements.
133 Services.geoForDocOrNull(this.ampdoc).then((geo) => {
134 this.cachedGeo_ = geo;
135 });
136
137 // Returns a random value for cache busters.
138 this.set('RANDOM', () => Math.random());
139
140 // Provides a counter starting at 1 per given scope.
141 const counterStore = Object.create(null);
142 this.set('COUNTER', (scope) => {
143 return (counterStore[scope] = (counterStore[scope] | 0) + 1);
144 });
145
146 // Returns the canonical URL for this AMP document.
147 this.set('CANONICAL_URL', () => this.getDocInfo_().canonicalUrl);
148
149 // Returns the host of the canonical URL for this AMP document.
150 this.set(
151 'CANONICAL_HOST',
152 () => parseUrlDeprecated(this.getDocInfo_().canonicalUrl).host
153 );
154
155 // Returns the hostname of the canonical URL for this AMP document.
156 this.set(
157 'CANONICAL_HOSTNAME',
158 () => parseUrlDeprecated(this.getDocInfo_().canonicalUrl).hostname
159 );
160
161 // Returns the path of the canonical URL for this AMP document.
162 this.set(
163 'CANONICAL_PATH',
164 () => parseUrlDeprecated(this.getDocInfo_().canonicalUrl).pathname
165 );
166
167 // Returns the referrer URL.
168 this.setAsync(
169 'DOCUMENT_REFERRER',
170 /** @type {AsyncResolverDef} */ (
171 () => {
172 return Services.viewerForDoc(this.ampdoc).getReferrerUrl();
173 }
174 )
175 );
176
177 // Like DOCUMENT_REFERRER, but returns null if the referrer is of
178 // same domain or the corresponding CDN proxy.
179 this.setAsync(
180 'EXTERNAL_REFERRER',
181 /** @type {AsyncResolverDef} */ (
182 () => {

Callers

nothing calls this directly

Calls 15

getDocInfo_Method · 0.95
getQueryParamData_Method · 0.95
getFragmentParamData_Method · 0.95
getVariantsValue_Method · 0.95
getGeo_Method · 0.95
getUach_Method · 0.95
setTimingResolver_Method · 0.95
getAccessValue_Method · 0.95
parseUrlDeprecatedFunction · 0.90
getSourceUrlFunction · 0.90
removeFragmentFunction · 0.90

Tested by

no test coverage detected