Back button not working after extension opens new URL

795 views
Skip to first unread message

Richard Miller

unread,
Jan 13, 2022, 2:59:03 PM1/13/22
to Chromium Extensions
Hi all!

I'm seeing an issue with the Back button when an extension opens new URLs.

Here's the scenario:
1. User has a single tab open to page A.
2. Extension calls chrome.tabs.update(tab_id, { url }) to open pages B, then C, then D. (This is over time, as part of a workflow.)
3. User clicks Back button.
4. Browser returns to page A, not page C.

However, if while page B was open, the user had clicked anywhere on the page, the Back button would return to page B.

Interestingly, if instead the user *right-clicks* the Back button, ALL the pages are visible starting with the most recent, e.g. C, B, A.

Therefore, it appears that if the extension opens a page, but the user doesn't interact with that page, it becomes part of the right-click history on the Back button, but not part of the history when (left-)clicking the Back button.

In addition to chrome.tabs.update(), I've also tried sending a message to a content script in the tab, which in turn calls `window.location.href = url`, but this has the same behavior as above.

On MDN, tabs.update() has an option for `loadReplace`[1]. It sounds like the behavior I want is `chrome.tabs.update(tab_id, { url, loadReplace: false })`. However, loadReplace does not exist in Chrome, and I haven't tried it on Firefox.

Chrome's behavior isn't exactly `loadReplace: true` nor `loadReplace: false` since interaction with a page seems to change the behavior.

Anyone else run into this issue, or recommend any workarounds? 

Best wishes,
Richard

[1] https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/Tabs/update

hrg...@gmail.com

unread,
Jan 13, 2022, 4:27:31 PM1/13/22
to Chromium Extensions, ric...@hireuseragent.com
I can reproduce this behavior too.

If you inject a "history.back()" script into the page, it goes back 1 step as expected.
If you call chrome.tabs.goBack() instead, it behaves the same as the back button.

I can't think of a workaround right now, other than going nuclear by using a native messaging host to inject a fake keystroke  that the browser sees as "user interaction".

wOxxOm

unread,
Jan 14, 2022, 10:04:40 AM1/14/22
to Chromium Extensions, hrg...@gmail.com, ric...@hireuseragent.com
To me this sounds like a bug in Chrome.

hrg...@gmail.com

unread,
Jan 14, 2022, 10:58:50 AM1/14/22
to Chromium Extensions, wOxxOm, hrg...@gmail.com, ric...@hireuseragent.com

To me this sounds like a bug in Chrome.
 
Sometimes, websites "redirect" to another page using Javascript. Then, if the user clicks on BACK, they go back to the page that redirects them again, ending up on the same page.
Some ill-intended websites use this trick.
So, it's possible that the browser is trying to prevent that situation.

Richard Miller

unread,
Jan 17, 2022, 7:07:04 PM1/17/22
to Chromium Extensions, hrg...@gmail.com, wOxxOm, Richard Miller
Thank you all for weighing in. I appreciate your thoughts!

hrg...@gmail.com

unread,
Feb 18, 2022, 12:53:04 PM2/18/22
to Chromium Extensions, ric...@hireuseragent.com, hrg...@gmail.com, wOxxOm
@Richard, did you ever report this issue?

Richard K. Miller

unread,
Feb 22, 2022, 7:12:53 PM2/22/22
to hrg...@gmail.com, Chromium Extensions, wOxxOm
No I never reported this. Is crbug.com the best place to report it? 

hrg...@gmail.com

unread,
Feb 22, 2022, 8:48:18 PM2/22/22
to Chromium Extensions, ric...@hireuseragent.com, wOxxOm, hrg...@gmail.com
I already reported it a few days ago.

Richard K. Miller

unread,
Feb 22, 2022, 10:07:01 PM2/22/22
to hrg...@gmail.com, Chromium Extensions, wOxxOm
Thanks for reporting it, and nicely done. I've starred it to follow along.
Reply all
Reply to author
Forward
0 new messages