“Not allowed to load local resource” error is seen while launching the chrome crash url

◇◆丶佛笑我妖孽 提交于 2021-01-29 05:12:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!