Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not allowed to load local resource: <URL> #456

Closed
xblack0 opened this issue Sep 19, 2020 · 12 comments
Closed

Not allowed to load local resource: <URL> #456

xblack0 opened this issue Sep 19, 2020 · 12 comments

Comments

@xblack0
Copy link

xblack0 commented Sep 19, 2020

Does any one find a way ? or got same this issue ?

@ukandrewc
Copy link

Not seeing that here, on Winforms (32bit)

2020-09-19_134454

@xblack0
Copy link
Author

xblack0 commented Sep 19, 2020

Not seeing that here, on Winforms (32bit)

is that webview2 control < default setup ?

@ukandrewc
Copy link

Not sure what you mean by default setup, but I'm not doing anything special to load the page.

@xblack0
Copy link
Author

xblack0 commented Sep 19, 2020

Not sure what you mean by default setup, but I'm not doing anything special to load the page.

did you try to load local resources such as picture or video files?

@ukandrewc
Copy link

Yes, the screenshot has an image, also navigated to page with video, all working as expected.

@champnic
Copy link
Member

@xblack0 Accessing local files with the "file:" protocol is expected to work in WebView2. Can you share some code where you are trying to do this or a sample app?

The file url needs to be an absolute path to the file, and your app needs to have read access on the file. So if you are building a UWP app, for example, your file needs to be in your app's folders (like app data, etc.).

Another thing to check is that the file exists where you think it does. Are you deploying your files to the place your app is looking for them?

@xblack0
Copy link
Author

xblack0 commented Sep 21, 2020

image

@champnic
Copy link
Member

Thanks for the added info. This is a security restriction built-into Chromium/Edge. Essentially http: served pages cannot access file: served content. Are other parts of your web ui using the http: protocol? There are workarounds described on StackOverflow:
https://stackoverflow.com/questions/37223209/js-file-not-loading-js-console-says-not-allowed-to-load-local-resource
https://stackoverflow.com/questions/34901523/file-url-not-allowed-to-load-local-resource-in-the-internet-browser

@xblack0
Copy link
Author

xblack0 commented Sep 21, 2020

Thanks for the added info. This is a security restriction built-into Chromium/Edge. Essentially http: served pages cannot access file: served content. Are other parts of your web ui using the http: protocol? There are workarounds described on StackOverflow:
https://stackoverflow.com/questions/37223209/js-file-not-loading-js-console-says-not-allowed-to-load-local-resource
https://stackoverflow.com/questions/34901523/file-url-not-allowed-to-load-local-resource-in-the-internet-browser

my application completely out of Http, I am using webview 2 as an interface instead of normal winform (.net vb)

@nnemkin
Copy link

nnemkin commented Feb 4, 2021

Pages created with NavigateToString (which uses data: protocol internally) can't access file:// resources either.
This makes it difficult to replace old IE with Edge.

I couldn't find a work-around. Using flags like --disable-web-security --allow-file-access-from-files --allow-file-access simply changes the error from "Not allowed to load local resource" to "Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME".

@xblack0
Copy link
Author

xblack0 commented Feb 4, 2021

Pages created with NavigateToString (which uses data: protocol internally) can't access file:// resources either.
This makes it difficult to replace old IE with Edge.

I couldn't find a work-around. Using flags like --disable-web-security --allow-file-access-from-files --allow-file-access simply changes the error from "Not allowed to load local resource" to "Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME".

there is a workaround, use the native app to load the resource file and injected it into your code,

@champnic
Copy link
Member

champnic commented Feb 5, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants