blob: 54c8a9766f4e1287f1316c7f96c6eb435a5f29ad [file] [log] [blame] [view]
shivanigithub2190650b2022-10-13 02:01:321# History manipulation intervention in Chromium
2
3Reference: [PSA on blink-dev](https://groups.google.com/a/chromium.org/g/blink-dev/c/T8d4_BRb2xQ/m/WSdOiOFcBAAJ)
4
5## Summary
6Some pages make it difficult or impossible for the user to use the browser back
7button to go back to the page they came from. Pages accomplish this using
8redirects or by manipulating the browser history, resulting in an
9abusive/annoying user experience.
10
11The history manipulation intervention mitigates such abuse by making the
12browsers back button skip over pages that added history entries or redirected
13the user without ever getting a user activation. Note that the intervention only
14impacts the browser back/forward buttons and not the `history.back()/forward()`
15APIs.
16
17Heres an example:
181) User is on a.com and clicks to go to b.com
192) b.com adds a history entry using `pushState` or navigates the user to another
20page (c.com) without ever getting a user activation.
213) If the user presses back, the browser will skip b.com and go back to a.com
22instead.
23
24## Spec
25Because this only impacts browser UI, this is allowed by the spec, which only
26governs the behavior of `history.back/forward`.
27However, it might be good to spec this anyway, so that users get consistent
28experiences in all browsers. That work is tracked at
29https://github.com/whatwg/html/issues/7832
30
31## Invariants
32The intervention guarantees the following invariants:
331. Only back/forward navigations triggered by the back/forward buttons will ever
34 skip history entries. This ensures that the history API's behavior is
35 unaffected.
362. The intervention marks a history entry as skippable if the document creates
37 another history entry without a user activation.
383. If a document receives a user activation (before or after creating history
39 entries), its history entry is not skippable. With an activation, the
40 document can create many unskippable same-document history entries, until
41 either a cross-document navigation or a back/forward occurs.
424. All same-document history entries will have the same skippable state. When
43 marking an entry unskippable after a user activation, this ensures that the
44 rest of the document's entries work as well. When marking an entry as
45 skippable, this ensures that all entries for the offending document will be
46 skipped.
475. Revisiting a skippable history entry does not change its skippable status,
48 unless it receives a user activation. This ensures that history.back() will
49 not bypass the intervention, per https://crbug.com/1121293.
506. The intervention applies to history entries created by subframes as well. A
51 user activation on any frame on the page is sufficient to make the entry
52 unskippable, per https://crbug.com/953056.
53
54## Details
551. The intervention works by setting the `should_skip_on_back_forward_ui_`
56 member for a `NavigationEntryImpl` object. The member is initially set to
57 false, and it is set to true if any document in the page adds a history entry
58 without having a user activation.
592. `NavigationController::CanGoBack()` will return false if all entries are
60 marked to be skipped on back/forward UI. On desktop this leads to the back
61 button being disabled. On Android, pressing the back button will close the
62 current tab and a previous tab could be shown as it would normally happen on
63 Android when the back button is pressed from the first entry of a tab.
643. The oldest `NavigationEntryImpl` that is marked as skippable is the one
65 that is pruned if max entry count is reached.