17

UPDATE

chrome://about/ has direct links to chrome://settings and others, so it can be done.

How can I link/redirect to a chrome:// URL in a webpage? For example, chrome://settings. When attempting to click a link to a chrome:// URL,

<a href="chrome://settings">link</a>

I get an error in the console:

Not allowed to load local resource: chrome://settings/

According to this answer, it is possible:

Link to chrome://chrome/extensions from extension options page

I've tried this script:

<a href="#" id="test">test</a>
<script>
document.addEventListener('DOMContentLoaded', function () {
    document.getElementById('test').addEventListener('click', function () {
        chrome.tabs.update({
            url: 'chrome://chrome/extensions'
        });
    });
});
</script>

And also this one:

<a href="#" onclick="chrome.tabs.create({url:'chrome://settings/clearBrowserData'});">click me</a>

Neither works. In addition to those, I've tried:

  • Linking to it using <a href="chrome://newtab">
  • Redirect the user using window.location.

However, I believe there may be a JavaScript workaround. When the user presses a link, is it possible to change the URL to chrome://settings? The user would have to press Enter after, but this seems like the best I'd get.

Community
  • 1
  • 1
mancestr
  • 969
  • 3
  • 13
  • 34
  • 1
    Where are you placing this JavaScript code and HTML? From your comment on the answer, it sounds like you are wanting to place this link in a webpage. Is that correct? However, your JavaScript code is using an extension specific API. – Makyen Nov 01 '16 at 16:21
  • potentially related: [The Chrome extension popup is not working, click events are not handled](http://stackoverflow.com/a/17612988/3773011) – Makyen Nov 01 '16 at 16:24
  • 1
    There is a big difference between code that will work in an extension, as is described on the page you link, [Link to chrome://chrome/extensions from extension options page](http://stackoverflow.com/questions/13125616/link-to-chrome-chrome-extensions-from-extension-options-page), and code that will work in a webpage. `chrome.tabs` is an extension specific API that is not available to webpages. [Now see Xan's answer](http://stackoverflow.com/a/40364397/3773011). – Makyen Nov 01 '16 at 16:33
  • 3
    `chrome://about/` is already a URL using the `chrome://` scheme (i.e. internal to Google Chrome). Claiming that you can link to a `chrome://` URL from a webpage based on there being links from a Chrome internal page is erroneous and a flawed comparison. It has already been clearly established that you can have such links from already privileged URLs/code (see answers detailing how to do so from an extension). – Makyen Nov 01 '16 at 16:57
  • Note: If providing an update to your question where you are only providing a little additional text and not changing the bulk of your Question, please separate the update from the bulk of your Question, so we do not have to go and look at the [edit diff](http://stackoverflow.com/posts/40362775/revisions) to see that is the case. The common way to do that is to place the update at the bottom of the question. – Makyen Nov 01 '16 at 17:01

2 Answers2

24

Nope, there is no way to do it from a webpage.

chrome:// is a privileged origin, and any attempt to open it will result in a redirect to about:blank.

Chrome does that to reduce the attack surface: even though just opening those URLs should be harmless, it's better not to allow websites and external programs to even try.

Besides, it's not that harmless, e.g. debug URLs like chrome://crash, chrome://hang (careful, those really do what you expect).

Obviously, you can't use chrome.tabs as it's an extension API not exposed to websites. It is, however, capable of opening privileged origins.

Xan
  • 74,770
  • 16
  • 179
  • 206
8

Below works for me;

manifest.json

 {
  "manifest_version": 2,

  "name": "Redirection Sample",
  "description": "Test Redirection",
  "version": "1.0",

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "permissions": [
    "activeTab",
    "https://ajax.googleapis.com/"
  ]
}

popup.html

<!doctype html>
<html>
  <head>
    <title>Redirection Popup</title>
    <script src="popup.js"></script>
  </head>
  <body>
  <a href="#" id="test">test</a>
  </body>
</html>

popup.js

  document.addEventListener('DOMContentLoaded', function() {
        document.getElementById('test').addEventListener('click', function() {
            chrome.tabs.update({ url: 'chrome://chrome/extensions' });
        });
    });

icon.png

Add a customized one or download a sample from this link

Include all these 4 inside one directory and load unpack the extension to chrome. It should work!

  • 2
    Hi- sorry about this, but I'm not looking for extensions, because my workplace blocks us from using any. I'd rather make a solution that works for any user without extensions – mancestr Nov 01 '16 at 16:15
  • 1
    Thank you, I had to change 'chrome://chrome/extensions' to 'chrome://extension' – f-CJ Jun 02 '20 at 11:44