Skip to content

Commit

Permalink
Implement viewer query param removal experiment.
Browse files Browse the repository at this point in the history
  • Loading branch information
William Chou committed Oct 21, 2019
1 parent 89a048d commit 4b579f6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/service/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
installServiceInEmbedScope,
registerServiceBuilderForDoc,
} from '../service';
import {isExperimentOn} from '../experiments';
import {toWin} from '../types';
import PriorityQueue from '../utils/priority-queue';

Expand Down Expand Up @@ -549,6 +550,25 @@ export class Navigation {
element.setAttribute('target', '_blank');
}
}

// Safari 13: Remove viewer's query params (e.g. amp_js_v, usqp) to prevent
// Document.referrer from being reduced to eTLD+1 (e.g. ampproject.org).
const platform = Services.platformFor(this.ampdoc.win);
const viewer = Services.viewerForDoc(element);
if (
isExperimentOn(
this.ampdoc.win,
'remove-viewer-query-params-on-navigate'
) &&
location.search &&
platform.isSafari() &&
platform.getMajorVersion() >= 13 &&
viewer.isProxyOrigin() &&
viewer.isEmbedded()
) {
const noSearch = `${location.origin}${location.pathname}${location.hash}`;
this.ampdoc.win.history.replaceState({}, '', noSearch);
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions tools/experiments/experiments.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@ const EXPERIMENTS = [
spec: 'https://github.com/ampproject/amphtml/issues/24168',
cleanupIssue: 'https://github.com/ampproject/amphtml/issues/24169',
},
{
id: 'remove-viewer-query-params-on-navigate',
name: 'Removes query params from viewer iframe on navigation.',
spec: 'https://github.com/ampproject/amphtml/issues/25179',
cleanupIssue: 'https://github.com/ampproject/amphtml/issues/24169',
},
];

if (getMode().localDev) {
Expand Down

0 comments on commit 4b579f6

Please sign in to comment.