Link to chrome:// url from a webpage

前端 未结 2 1482
广开言路
广开言路 2020-12-30 10:27

UPDATE

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

How can I link/redirect to a

相关标签:
2条回答
  • 2020-12-30 11:04

    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.

    0 讨论(0)
  • 2020-12-30 11:10

    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!

    0 讨论(0)
提交回复
热议问题