Code Monkey home page Code Monkey logo

webview2.winforms.jshelper's Introduction

WebView2.Winforms.JSHelper

Extensions to allow easier coding and debugging of ExecuteScriptAsync in WebView2

The inspiration was to try and get as close as possible to inline editing of javascript for executing in WebView2.

The library allows you to execute scripts from file in debug, and as from resources in release. When in release it will execute a minfied version from resources, if there is one.

In debug you can then edit your scripts in a decent editor instead of strings or resources, and without having to recompile to update the script.

The library also includes a RunSync function and method, as an extension of Task to run tasks synchronously.

Usage

  • Add your .js scripts to a folder in your project.
  • Add the same file (or minified version) to your project as resource.

If you want to minify your script, then add the minified file to your resources with _min appended to the name.

image

Execute your script using the ExecuteScriptResourceAsync or ExecuteScriptResourceSync

e.g.

Res = Web.CoreWebView2.ExecuteScriptResourceSync(relative_path)

Task = Web.CoreWebView2.ExecuteScriptResourceAsync(relative_path)

Private Sub TestFrm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
	Web.EnsureCoreWebView2Async.RunSync
	Web.CoreWebView2.SetResourceManager(My.Resources.ResourceManager)
	Web.CoreWebView2.Navigate("https://w3.org/WAI/UA/2002/06/thead-test")
End Sub

Private Sub Web_NavigationCompleted(sender As Object, e As CoreWebView2NavigationCompletedEventArgs) Handles Web.NavigationCompleted
	Web.CoreWebView2.ExecuteScriptResourceSync("Script\test.js")
End Sub

When in debug, this will load the script from the named relative_path. In release, it will load the resource with the same name or minified version, if there is one.

Debugging

When the DevTools window is open, adding the command debugger, to you script will pause the script at that line. You can then inspect and set other breakpoints in your script.

webview2.winforms.jshelper's People

Contributors

ukandrewc avatar

Stargazers

 avatar Alex Lira avatar  avatar José Luis avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

m8e

webview2.winforms.jshelper's Issues

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.