file:// protocol and webview in nw13

617 views
Skip to first unread message

hkaya

unread,
Feb 15, 2016, 10:34:10 AM2/15/16
to nw.js
Hi all,

Does anybody know how to use a local file stored out of the app directory as the webview source? In NW12, I could just provide the absolute path of a local html file:

<webview src="/home/xxx/index.html" ...></webview>

With NW13, the default protocol has changed to chrome-extension://, so the above method no longer works. I can explicitly use the file:// protocol anywhere else: e.g. file:///home/xxx/image.jpg works within my main application. However, I can't use the file:// protocol as webview source. This is the error I'm getting:

<webview src="file:///home/xxx/index.html" ...></webview>

<webview>: The load has aborted with error -301: ERR_DISALLOWED_URL_SCHEME.

Any ideas or workarounds?

I'm testing with 0.13.0-beta5sdk-1 on linux. 

Thank you!

lza...@gmail.com

unread,
Feb 15, 2016, 12:05:49 PM2/15/16
to hkaya, nw.js
Hi,
Wondering if you have to use partition and define it in package.json
Read the "Accessing packaged resources" here

I usually load remote content and no issues with that. 
So you are storing the html at an arbitrary location and want to load it in? I am curious now I might experiment. 

Hope it helps. 

Laszlo

--
You received this message because you are subscribed to the Google Groups "nw.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwjs-general...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hkaya

unread,
Feb 15, 2016, 12:27:24 PM2/15/16
to nw.js, hamz...@gmail.com
Hey Laszlo,

Yes, I'm trying to load files stored outside of the packaged app directory. So I need to access them using the file:// protocol.

I think that section refers to resources included in a Chrome app. As far as I see, I can access those resources even without specifying them in manifest. My guess is file protocol is simply disabled for webview tag. This might have always been the case but it's causing issues with NW13 now because whenever I use an absolute path, it gets converted to the chrome-extension url.

I got the same error with the following setting:

package.json:
  "permissions": [
      "webview"
  ],
  "webview": {
      "partitions": [
          {"name": "trusted*",
              "accessible_resources": ["*.html", "*.js"]}  # adding the absolute path of the html doesn't work as well                                                                                                                                    
      ]
  },

<webview partition="trustedwebview" src="file:///..."></webview>


--allow-file-access-from-files and / or --allow-file-access flags also doesn't help.

The odd part is, I can load files just fine with an iframe. The url scheme restriction on webview seems strange in the context of nwjs. 

lza...@gmail.com

unread,
Feb 15, 2016, 1:42:40 PM2/15/16
to hkaya, nw.js
Hi,

On Feb 15, 2016, at 09:27, hkaya <hamz...@gmail.com> wrote:

Hey Laszlo,

Yes, I'm trying to load files stored outside of the packaged app directory. So I need to access them using the file:// protocol.

I think that section refers to resources included in a Chrome app. As far as I see, I can access those resources even without specifying them in manifest. My guess is file protocol is simply disabled for webview tag. This might have always been the case but it's causing issues with NW13 now because whenever I use an absolute path, it gets converted to the chrome-extension url.

I got the same error with the following setting:

package.json:
  "permissions": [
      "webview"
  ],
  "webview": {
      "partitions": [
          {"name": "trusted*",
              "accessible_resources": ["*.html", "*.js"]}  # adding the absolute path of the html doesn't work as well                                                                                                                                    
      ]
  },

<webview partition="trustedwebview" src="file:///..."></webview>


--allow-file-access-from-files and / or --allow-file-access flags also doesn't help.

The odd part is, I can load files just fine with an iframe. The url scheme restriction on webview seems strange in the context of nwjs. 

You just answered my other question if it works with iframe. 
You got me curious now so I will try your setup later today :)

Silly question and you might already checked that but do you have read permission on those files?


Laszlo 

hkaya

unread,
Feb 16, 2016, 12:23:35 PM2/16/16
to nw.js, hamz...@gmail.com
Hi,

Unfortunately, this is not a file permission problem, that'd make it some much easier! I can load files in an iframe just fine. Replacing iframe tag with webview throws the url scheme error. 

Roger Wang

unread,
Feb 20, 2016, 7:42:02 PM2/20/16
to nw.js, hamz...@gmail.com
Thanks for reporting. Will like to fix it soon.

You're right that NW takes a different security model from Browser. We provide a native security model for trusted code while remains the strict W3C model for untrusted contents. So any feature requests under the native model are welcomed.

Roger
Reply all
Reply to author
Forward
0 new messages