New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 830622 link

Starred by 4 users

Issue metadata

Status: Fixed
Owner:
Last visit 27 days ago
Closed: Nov 8
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Windows , Chrome , Mac
Pri: 3
Type: Feature



Sign in to add a comment

[Feature Request] [Extensions API] Method to navigate back and forward

Reported by hrg....@gmail.com, Apr 9 2018

Issue description

For Chrome extension developers, there's currenlty no method in the chrome.tabs API to navigate back and forward for a given tab.

There's the chrome.tabs.update method which allows us to navigate to a different URL. There's also the chrome.tabs.reload method for reloading the page. But, surprisingly, no method to navigate back and forward.

Currently, the only workaround is to do this:
chrome.tabs.executeScript(tabId, {code:"history.back()"})

Unfortunately, that solution is not acceptable because it won't work on many situations, namely:
- Pages where Javascript is disabled
- Error pages (e.g 404 errors, network errors, etc.)
- Security warning pages
- Chrome Web Store pages
- Extension tabs
- App tabs
- "chrome://" tabs
- "view-source:" tabs
- "data:" tabs
- "Aw, Snap!" tabs

What we need is a reliable way to trigger a navigate-back/forward action. This would allow us to customize shortcuts for such actions (which is an area where Chrome is really lacking).

Please, consider the suggestion.
 
Labels: Needs-Milestone
Labels: -Type-Bug Type-Feature
Status: Untriaged (was: Unconfirmed)
Since this is a feature request marking it as untriaged
Components: Platform>Extensions>API

Comment 4 by hrg....@gmail.com, Apr 12 2018

A good example of this problem is the extension "Go Back With Backspace" made by Google.
https://chrome.google.com/webstore/detail/go-back-with-backspace/eekailopagacbcdloonjhbiecobagjci

As the extension relies on Javascript injection, it simply doesn't work on all those cases listed in the first post. And that is quite frustrating for the user.
Cc: rdevlin....@chromium.org
Labels: OS-Chrome OS-Linux OS-Mac
Status: Available (was: Untriaged)
This sounds pretty reasonable to me - I think it would be a useful API, and would be good to help avoid the need for extensions to inject code into web pages if they don't need to.

I'm not sure it's something we'll tackle in the near future, so marking as available for now.  If anyone wanted to take this on, the process for expanding extension APIs is documented here: https://chromium.googlesource.com/chromium/src/+/master/extensions/docs/new_api_proposal.md
My two cents:
It might better to create new api category like chrome.navigate.[goback].
I know we already have reload api in chrome.tabs, but presently chrome.tabs has too many inconsistency functions. I think we should stop adding uncategorized functions into chrome.tabs.

@hrg.wea@gmail.com,
Thank you for sharing idea. Are you going to write API proposal?
@#6
I read the document linked by #5 and the whole process seems prohibitive for an independent developer like me.
The document establishes ownership and responsibilities that I can't take being an outsider.
Owner: lima...@gmail.com
@hrg.wea
I'd just like to share information while proposing this API to extension team.
With this API, we sill cannot use 'backspace' as shortcut to navigate back. That's because the shortcuts created by command API[1] must include either Ctrl* or Alt. 

If you have any other good use case for this API, could you share it?

[1] https://developer.chrome.com/extensions/commands
The particular case of backspace as a shortcut involves a more serious difficulty, which is, being able to detect when the keyboard focus is on a text input field or not.
Without such a detection, pressing backspace would produce undesired effects when editing text.

Currently, there's no API to detect that condition, so javascript injection is the only way around it.

For all that, the backspace use case is not the best example for the usefulness of the back/forward API.

Better examples may be:

1. Command-API shortcuts, as you mentioned.

2. Macro creation.
   An extension that could allow the creation of automation macros, giving the user a list of possible actions to perform on existing tabs or windows.
   You want to avoid relying on script injection for this because it's unreliable, as explained in the original post. Popular extensions like TamperMonkey could benefit from this.

3. The ability to perform the back/forward action on multiples tabs simultaneously, which works reliably even on protected tabs and with no need for the <all_urls> permission.

4. Define actions in response to events.
   The back/forward buttons do more than just page-to-page navigation. On single-page apps they work as a UI navigation mechanism.
   It would be possible to have an extension that allowed the user to define a back/forward action (and other actions as well) for a given tab in response to browser events like when a tab is activated, when a window is focused, when a tab is opened/closed, when a tab becomes audible, when a tab decides to navigate to another page on its own (Youtube). The possibilities are endless, really.

Project Member

Comment 11 by bugdroid1@chromium.org, Nov 2

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/265d9c20b65dbf38ddb288b0fd885461c28c57ad

commit 265d9c20b65dbf38ddb288b0fd885461c28c57ad
Author: Sungguk Lim <limasdf@gmail.com>
Date: Fri Nov 02 03:23:31 2018

Implement chrome.tabs.goBack and chrome.tabs.goForward

Implementation for chrome.tabs.goBack and chrome.tabs.goForward
Above APIs provide a reliable way to trigger a navigate-back/forward
action like back/forward button on toolbar.

Bug:  830622 
Change-Id: I1f5e8d5e4768161f43b2df1621a03a6cc3383b4f
Reviewed-on: https://chromium-review.googlesource.com/c/1274225
Reviewed-by: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604831}
[modify] https://crrev.com/265d9c20b65dbf38ddb288b0fd885461c28c57ad/chrome/browser/extensions/api/tabs/tabs_api.cc
[modify] https://crrev.com/265d9c20b65dbf38ddb288b0fd885461c28c57ad/chrome/browser/extensions/api/tabs/tabs_api.h
[modify] https://crrev.com/265d9c20b65dbf38ddb288b0fd885461c28c57ad/chrome/browser/extensions/api/tabs/tabs_api_unittest.cc
[modify] https://crrev.com/265d9c20b65dbf38ddb288b0fd885461c28c57ad/chrome/browser/extensions/api/tabs/tabs_constants.cc
[modify] https://crrev.com/265d9c20b65dbf38ddb288b0fd885461c28c57ad/chrome/browser/extensions/api/tabs/tabs_constants.h
[modify] https://crrev.com/265d9c20b65dbf38ddb288b0fd885461c28c57ad/chrome/common/extensions/api/tabs.json
[modify] https://crrev.com/265d9c20b65dbf38ddb288b0fd885461c28c57ad/extensions/browser/extension_function_histogram_value.h
[modify] https://crrev.com/265d9c20b65dbf38ddb288b0fd885461c28c57ad/tools/metrics/histograms/enums.xml

Status: Fixed (was: Available)
Hi hrg.wea,

This feature is now available on canary build.
@lima, this is great.

Thanks for doing this.

Sign in to add a comment