我正在尝试使用本地文件设置webview的源。
清单:
"webview": {
"partitions": [{
"name": "static",
"accessible_resources": [
"sandbox/sandbox.html",
"sandbox/sandbox.js",
"sandbox/sandbox.css",
]
}]
},
设置Webview的来源
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>
错误:
<webview>: The load has aborted with error -109: ERR_ADDRESS_UNREACHABLE.
为什么会这样,我该如何解决这个问题?
此设置有效:
/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
此设置返回地址无法访问&#39;错误:
/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
答案 0 :(得分:0)
<webview>
适用于外部内容。
要embed your own sandboxed pages,请使用<iframe>
。
此外,显然使用相对路径非常重要 - getURL
会返回与预期不同的URI方案。