问题
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.
Is there any way I can launch the chrome crash url through window.open without receiving the error ?
Here is what I tried :
<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>
回答1:
- 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.
Solution 1.
A chrome extension can send Browser.crash command via chrome.debugger API.
manifest.json excerpt:
"permissions": ["debugger"]
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');
});
});
Solution 2.
The same command can be sent by an external CDP tool like puppeteer (example).
来源:https://stackoverflow.com/questions/61745046/not-allowed-to-load-local-resource-error-is-seen-while-launching-the-chrome-cr