Skip to content

Commit

Permalink
Make DocInfo.pageViewId64 async (#23998)
Browse files Browse the repository at this point in the history
* Make DocInfo.pageViewId64 async.

* Fix types.
  • Loading branch information
William Chou committed Aug 16, 2019
1 parent 7014745 commit afe7a4c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/service/document-info-impl.js
Expand Up @@ -73,6 +73,8 @@ export class DocInfo {
this.ampdoc_ = ampdoc;
/** @private {?DocumentInfoDef} */
this.info_ = null;
/** @private {?Promise<string>} */
this.pageViewId64_ = null;
}

/** @return {!DocumentInfoDef} */
Expand All @@ -92,7 +94,6 @@ export class DocInfo {
: sourceUrl;
}
const pageViewId = getPageViewId(ampdoc.win);
const pageViewId64 = getRandomString64(ampdoc.win);
const linkRels = getLinkRels(ampdoc.win.document);
const metaTags = getMetaTags(ampdoc.win.document);
const replaceParams = getReplaceParams(ampdoc);
Expand All @@ -104,7 +105,15 @@ export class DocInfo {
},
canonicalUrl,
pageViewId,
pageViewId64,
get pageViewId64() {
// Must be calculated async since getRandomString64() can load the
// amp-crypto-polyfill on some browsers, and extensions service
// may not be registered yet.
if (!this.pageViewId64_) {
this.pageViewId64_ = getRandomString64(ampdoc.win);
}
return this.pageViewId64_;
},
linkRels,
metaTags,
replaceParams,
Expand Down

0 comments on commit afe7a4c

Please sign in to comment.