Skip to content

Commit

Permalink
Reduce noise in browser history on Chrome
Browse files Browse the repository at this point in the history
Closes #46
  • Loading branch information
qsantos committed Oct 14, 2024
1 parent 92b5d10 commit e823401
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.1.26

- Reduce noise in browser history on Chrome #46

# v0.1.25

- Only annotate the first 10 links (the ones with matching number hotkeys) #43
Expand Down
11 changes: 10 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,11 @@ chrome.storage.sync.get((options) => {

function gotoTop() {
const l = document.location;
// NOTE: we use history.replaceState() instead of location.replace() to
// avoid a page reload, which would happen since the new URL does not
// have a hash. This will result in a new entry in the browser history,
// but this only happen for the top element, which limits the number of
// entries.
history.replaceState(null, "", l.pathname + l.search);
deactivateCurrentThing();
scrollTo(0, 0);
Expand All @@ -995,7 +1000,11 @@ chrome.storage.sync.get((options) => {
// user navigates through many things in a short amount of time
clearTimeout(historyUpdateTimer);
historyUpdateTimer = setTimeout(() => {
history.replaceState(null, "", `#${thing.id}`);
// NOTE: we use location.replace() instead of
// history.replaceState() here to avoid adding entries to the
// browser history for each navigation. Unfortunately, Firefox
// still add entries to the browser history.
location.replace(`#${thing.id}`);
historyUpdateTimer = null;
}, 50);
// Immediately makes the change visible
Expand Down

0 comments on commit e823401

Please sign in to comment.