问题描述
更新
chrome://about/
有到 chrome://settings
和其他的直接链接,所以它可以做到.
chrome://about/
has direct links to chrome://settings
and others, so it can be done.
如何链接/重定向到网页中的 chrome://
网址?例如,chrome://settings
.尝试单击指向 chrome://
网址的链接时,
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:
从扩展链接到 chrome://chrome/extensions选项页面
我试过这个脚本:
<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>
还有这个:
<a href="#" onclick="chrome.tabs.create({url:'chrome://settings/clearBrowserData'});">click me</a>
两者都不起作用.除此之外,我还尝试过:
Neither works. In addition to those, I've tried:
但是,我相信可能有一个 JavaScript 解决方法.当用户按下链接时,是否可以将 URL 更改为 chrome://settings
?用户必须在之后按 ,但这似乎是我得到的最好的方法.
推荐答案
Nope, there is no way to do it from a webpage.
chrome://
是一个特权来源,任何打开它的尝试都将导致重定向到 about:blank
.
Chrome 这样做是为了减少攻击面:即使只是打开那些网址应该是无害的,但最好不要让网站和外部程序尝试.
此外,它也不是那么无害,例如调试 URL 像 chrome://crash
、chrome://hang
(小心,那些真的做你期望的).
显然,您不能使用 chrome.tabs
,因为它是一个未向网站公开的扩展 API.但是,它能够打开特权来源.
这篇关于从网页链接到 chrome://url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!