Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporarily remove query params from viewer iframe on navigate #25181

Merged
merged 9 commits into from Oct 25, 2019

Conversation

dreamofabear
Copy link

@dreamofabear dreamofabear commented Oct 21, 2019

Closes #25179.

This prevents document.referrer downgrade to eTLD+1, but valid query params will still be lost e.g. foo.example/article?id=12345.

  • Removes query params from viewer iframe before navigation (Safari 13+, cache origin only).
  • Restores query params async (opening new tab) or on "pageshow" (top navigation).

Tested on Safari 13 desktop with UA emulation.

@dreamofabear dreamofabear marked this pull request as ready for review October 24, 2019 16:06
@dreamofabear dreamofabear changed the title Remove viewer query params on navigate Temporarily remove query params from viewer iframe on navigate Oct 24, 2019
@dreamofabear
Copy link
Author

/to @zhouyx @jridgewell

src/service/navigation.js Show resolved Hide resolved

// For blank_, restore query params after the new page opens.
if (target === '_blank') {
win.setTimeout(restoreQuery, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timer.delay?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it buy us anything? Also:

This uses a micro task for 0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly the micro task. Do we need a macro task for this to work?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, tried it.


const restoreQuery = () => {
dev().info(TAG, 'Restored URL with query string:', original);
win.history.replaceState(null, '', original);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the order of timeouts, we may need to check that the URL is still the noQuery URL before replacing it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check and dev().error if it doesn't match.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also restore query params that also got appended before navigation. For example the linker param?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linker appends a query param to the viewer iframe? I thought it decorates the outgoing link.

In any case, this is the last code that runs before navigation including any URL expansion etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, nvm I was confused by all the urls....😅
LGTM

@zhouyx
Copy link
Contributor

zhouyx commented Oct 24, 2019

I noticed you put temporarily to the PR description. are there any long term solution be considered?

@dreamofabear
Copy link
Author

This is the long-term solution. :) "Temporarily" is only because we quickly restore the query params after opening a new tab or back navigation.

Copy link
Contributor

@zhouyx zhouyx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Defer to @jridgewell on the usage of bfcache


// For blank_, restore query params after the new page opens.
if (target === '_blank') {
win.setTimeout(restoreQuery, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly the micro task. Do we need a macro task for this to work?

src/service/navigation.js Show resolved Hide resolved
@dreamofabear
Copy link
Author

@jridgewell Need bundle size approval please. :)

@dreamofabear dreamofabear merged commit acd2fb3 into ampproject:master Oct 25, 2019
@dreamofabear dreamofabear deleted the safari-viewer-params branch October 25, 2019 20:38
micajuine-ho pushed a commit to micajuine-ho/amphtml that referenced this pull request Dec 27, 2019
…oject#25181)

* Implement viewer query param removal experiment.

* Dev error when removing unknown params.

* Tweak error message.

* Restore query params async or on pageshow.

* Enable in canary.

* Fix lint.

* Check that iframe URL hasn't changed before restoration.

* s/location/fromLocation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Safari 13: Viewer query params cause document.referrer downgrade
4 participants