Chrome app: sandbox resource address unreachable

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

I am trying to set a webview's source using a local file.

Manifest:

  "webview": {     "partitions": [{       "name": "static",       "accessible_resources": [         "sandbox/sandbox.html",         "sandbox/sandbox.js",         "sandbox/sandbox.css",       ]     }]   }, 

Set Webview's source

  var webviewSrc = chrome.runtime.getURL('sandbox/sandbox.html');   //console.log prints chrome-extension://MY_CHROME_APP_ID/sandbox/sandbox.html   webviewEl = <webview id="webview" ref="Webview" src={webviewSrc} partition="static"></webview> 

Error:

<webview>: The load has aborted with error -109: ERR_ADDRESS_UNREACHABLE. 

Why is it happening, and how do I fix this issue?

This setting works:

/foreground/main.html

<html>   <head>     <link rel="stylesheet" type="text/css" href="./bundle/app.css">     <link rel="stylesheet" type="text/css" href="./main.css">   </head>   <body>     <div id="app"></div>      <div id="webview-container">       <webview id="youtube-webview" src="sandbox/sandbox.html" partition="static"></webview>     </div>      <script src="./bundle/app.js"></script>   </body> </html> 

/sandbox/sandbox.html

Hello 

This setting returns 'address unreachable' error:

/foreground/main.html

<html>   <head>     <link rel="stylesheet" type="text/css" href="./bundle/app.css">     <link rel="stylesheet" type="text/css" href="./main.css">   </head>   <body>     <div id="app"></div>     <script src="./bundle/app.js"></script> <-- initialize webview inside here   </body> </html> 

/sandbox/sandbox.html

Hello 

/foreground/bundle/app.js

var webviewSrc = chrome.runtime.getURL('sandbox/sandbox.html'); // or var webviewSrc = 'sandbox/sandbox.html'; webviewEl = _react2.default.createElement("webview", { id: "webview", ref: "Webview", src: webviewSrc, partition: "static" }); // ADDRESS_UNREACHABLE 

回答1:

<webview> is for external content.

To embed your own sandboxed pages, use <iframe>.

Also, apparently it's important to use relative paths - getURL returns a different URI scheme from what's expected.



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