Giter VIP home page Giter VIP logo

Comments (5)

mattkol avatar mattkol commented on May 25, 2024

@VAllens apologies for the late response.

If you mean WebView2 core assemblies? At the beginning they were. I am not sure now that is it GA. But you can try.
If you mean something else. Please explain.

Thanks.

from edgesharp.

VAllens avatar VAllens commented on May 25, 2024

@mattkol
I searched google for the keyword SetVirtualHostNameToFolderMapping and found this place.

I have some static resource files (html, js, css, etc...).
If I decide not to embed them in an assembly resource,
then I can use the SetVirtualHostNameToFolderMapping method to map them to a local folder so they are ready to use out of the box.
If I decide to embed them in an assembly resource,
then I need to do extra work to handle some events, parse the request, and fetch the target resource from the assembly resource and finally respond.

I decide to embed them in an assembly resource, i solved it.

from edgesharp.

VAllens avatar VAllens commented on May 25, 2024

I don't want these static resource files to be exposed to users or visible in any directory on the computer.
And to prevent users from tampering with these static resource files, I embed them in the assembly resources.

from edgesharp.

mattkol avatar mattkol commented on May 25, 2024

I decide to embed them in an assembly resource, i solved it.

Cool! If this something you think will be useful for others, you can share a bare skeletal version.
Thanks.

from edgesharp.

VAllens avatar VAllens commented on May 25, 2024

Of course. Let's embrace open source !!!

I will take the time to organize the code and then share it.
Here are a few methods and events to keep an eye on:

  • CoreWebView2InitializationCompleted
  • CoreWebView2.WebResourceRequested
  • CoreWebView2.AddWebResourceRequestedFilter($"file://your_custom_alias/*", CoreWebView2WebResourceContext.All)
  • CoreWebView2.Environment.CreateWebResourceResponse(...)
  • Assembly.GetExecutingAssembly().GetManifestResourceStream(...)

We register the CoreWebView2InitializationCompleted event.
Then in the CoreWebView2InitializationCompleted callback method,
we register the internal events of CoreWebView2.WebResourceRequested and call CoreWebView2.AddWebResourceRequestedFilter method.

We process the file:// request in the CoreWebView2.WebResourceRequested callback method,
fetch the assembly resource file by relative URL, and respond stream.

Be careful. Be sure to use file:// instead of http://.
Issues: 2 seconds delay is seen with Page navigation using WebView2 & SetVirtualHostNameToFolderMapping

from edgesharp.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.