问题描述
出于我的应用程序测试目的,我想在单独的窗口中将Chrome网址崩溃,但是下面的代码给了我不允许加载本地资源"错误.
I want to crash the chrome url in a separate window for my application testing purpose,But the below piece of code gives me 'Not allowed to load local resource' error.
有什么办法可以通过window.open启动chrome崩溃URL而不收到错误吗?
Is there any way I can launch the chrome crash url through window.open without receiving the error ?
这是我尝试过的:
<html>
<head>
<title>Sample Test</title>
<script type="text/javascript">
function crashTest() {
window.open("chrome://inducebrowsercrashforrealz", "windowInMyApp", "left=50, top=100, width=600, height=400, toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
}
</script>
</head>
<body>
<div>
<br />
<button onclick="crashTest();">Navigate</button>
</div>
</body>
</html>
推荐答案
- 网页无法导航到
chrome://
URLs 故意. - 不允许使用普通扩展程序API(例如chrome.tabs或chrome.windows)打开导致浏览器/渲染器进程崩溃的URL 有意地.
- Web pages can't navigate to
chrome://
URLs intentionally. - Normal extension API like chrome.tabs or chrome.windows aren't allowed to open a URL that crashes the browser/renderer process intentionally.
chrome扩展可以发送 Browser.crash
命令通过 chrome.debugger API.
A chrome extension can send Browser.crash
command via chrome.debugger API.
manifest.json摘录:
manifest.json excerpt:
"permissions": ["debugger"]
browser_action的popup.js或background.js:
browser_action's popup.js or background.js:
chrome.tabs.create({url: 'about:blank', active: false}, ({id: tabId}) => {
chrome.debugger.attach({tabId}, '1.3', () => {
chrome.debugger.sendCommand({tabId}, 'Browser.crash');
});
});
同一命令可以由外部CDP工具(例如puppeteer(示例).
The same command can be sent by an external CDP tool like puppeteer (example).
这篇关于“不允许加载本地资源";启动Chrome浏览器崩溃URL时看到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!