Chrome应用:沙盒资源地址无法访问 [英] Chrome app: sandbox resource address unreachable

查看:109
本文介绍了Chrome应用:沙盒资源地址无法访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用本地文件设置Webview的源.

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

清单:

  "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.

为什么会发生,如何解决此问题?

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

此设置有效:

/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

此设置返回地址无法访问"错误:

/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

推荐答案

<webview>用于外部内容.

嵌入自己的沙盒页面,请使用<iframe>.

此外,使用相对路径显然很重要-getURL返回与预期不同的URI方案.

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

这篇关于Chrome应用:沙盒资源地址无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆