Giter Club home page Giter Club logo

go-webview2's People

Contributors

asv7c2 avatar frazeradam avatar gizmo-ds avatar jchv avatar leaanthony avatar marktohark avatar mikeschaap avatar nomis51 avatar sffxzzp avatar slonm avatar stffabi avatar vinhjaxt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-webview2's Issues

webview failing to start

While testing the demo, i am getting this error:

2022/02/10 17:34:15 Result: 80070002
2022/02/10 17:34:15 Failed to load webview.

What I could be doing wrong? I'm using Go 1.17.6, Windows 10 21H1 and have downloaded and installed WebView2 runtime.

Nevermind, seems like i had to download "Evergreen Bootstrapper" too

How Use Chrome Dev Protocol

Can you webview2 to show how to use the API call functions in the devtools?
How to get up and down in the websocket data in the current site?
Or you can contact me。 I am willing to pay a little reward。
Thank you

js window.talk No voice

js:
const synth = window.speechSynthesis;
const msg = new SpeechSynthesisUtterance();
function talk(text){
msg.text = text;
msg.lang = 'zh-CN';
msg.volume = '1';
msg.rate = 1;
msg.pitch = 1;
synth.speak(msg);
}

w.Eval("talk('test')") No voice

WebView2 error message

This appears on the console on exit: [0925/110501.167:ERROR:window_impl.cc(114)] Failed to unregister class Chrome_WidgetWin_0. Error = 0

There's a few references to it but the most specific I can find is this PR from 2012. It can probably safely ignored?

panic when calling PutDefaultBackgroundColor

when running this code:

c := edge.COREWEBVIEW2_COLOR{
		A: 100,
		R: 255,
		G: 255,
		B: 255,
	}
wv.Controler2.PutDefaultBackgroundColor(c)

i get:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x3963a4]

goroutine 1 [running, locked to thread]:
github.com/jchv/go-webview2/pkg/edge.(*ICoreWebView2Controller2).PutDefaultBackgroundColor(0xc00001e060, {0x64, 0xff, 0xff, 0xff})
        F:/........./go-webview2/pkg/edge/ICoreWebView2Controller2.go:65 +0x44

How to solve the cross domain problem of js?

   Access to script at 'file:///D:/goproject/src/test-webview/app/assets/client.80aeb8cb.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome-untrusted, https, edge.

tag version

please push a tag such as v1.0.0 or v0.1.0

MSHTML for Windows

I see that Edge WebView2 is being used with Windows, but Windows doesn't have robust support for that. For example, I am on Windows 10 2022 Update (10.0.19045), and it is not pre installed.

DevTools

Just found this project for Windows. Joy to work with so far. Much better then the built in webview as far as abilities go.

One thing that I wasn't able to do though was turn off DevTools by setting debug to false (or just passing false directly into webview2.New(). Otherwise it works perfectly from what I have been testing with it.

Is there something else that I need to do to turn off DevTools or is it possible to turn off DevTools for Webview2?

Window title is initially empty

When allowing the library to create a new window, the window title is initially empty. Even if the calling code uses SetTitle ASAP, there is a period of time (between the window being created and the browser instance finishing being initialised) when the window title has no text. This is problematic for accessibility clients (e.g. screen readers), as users will be informed about the presence of an untitled window.

It would be good for WebViewOptions to accept a WindowTitle string, allowing the window title to be set as early as possible.

Frameless and fixed position possible?

Hi, I have a small background application which sits in the Tray. Via menu entry there one can open a little WebView2 front-end. In this case I would like to open it without any system frame and next to the Tray with a fixed position. Would something like this be possible with WebView2? I could image it's even totally independent to WebView2 and I just miss the knowledge of doing it with syscalls etc. TIA.

webviewloader.GetInstalledVersion bugs

I found a few bugs in GetInstalledVersion in webviewloader:

  • It uses the err return from Call (which in turn calls GetLastError) when it should use the HRESULT that comes back in the first error. This results in the most recently posted error "The specified module could not be found." being erroneously reported from the failed attempt to load the DLL as a file (which since I'm relying on the embedded one will always fail).
  • A copy paste error exists where a code path calls nativeCompareBrowserVersions.

The outcome of this is that I have no good way to detect if WebView2 is installed, and thus if I need to trigger installation.

I experimented and found what I believe is a fix:
frazeradam#1

Resizing window

Is there an option to allow or an allow windows resizing?

WebView2Controller2

Opening a discussion about how we may use QueryObject to get hold of a WebView2Controller2 from the IWebView2 object. I've been unsuccessful so far.

How to hide titlebar?

How to hide titlebar and App can be moved ?
i try to hide titlebar with Hwnd, and html set
webkit-app-region: drag
but it can't move ...

Webview2Loader.dll not detected

Hey there 😄 Looks like webviewloader cannot detect WebView2Loader.dll in every scenario except if it is alongside the binary. Is that because the official DLL isn't in a default library directory? Cheers.

Capture Navigation Events

Hi, I am trying to find a way to capture navigation events used in windows webview2 (link). I couldnt find any in the WebView interface, but found some events are implemented in edge package inside Chromium struct

	envCompleted          *iCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler
	controllerCompleted   *iCoreWebView2CreateCoreWebView2ControllerCompletedHandler
	webMessageReceived    *iCoreWebView2WebMessageReceivedEventHandler
	permissionRequested   *iCoreWebView2PermissionRequestedEventHandler
	webResourceRequested  *iCoreWebView2WebResourceRequestedEventHandler
	acceleratorKeyPressed *ICoreWebView2AcceleratorKeyPressedEventHandler
	navigationCompleted   *ICoreWebView2NavigationCompletedEventHandler

Is there any way to add a handler for SourceChanged event of webview2 ?

Eval doesn't appear to work

Just tried using it on master branch and it didn't appear to work. Rolled back to previous commit, and it still doesn't appear to do anything. Here is the code I'm using to test it:

func main() {
	debug := true
	w := webview2.New(debug)
	if w == nil {
		log.Fatalln("Failed to load webview.")
	}
	defer w.Destroy()
	w.SetTitle("Minimal webview example")
	w.SetSize(800, 600, webview2.HintFixed)
	w.Navigate("https://en.m.wikipedia.org/wiki/Main_Page")
	go func() {
		runtime.LockOSThread()
		for i:=0; i<10; i++ {
			time.Sleep(3 * time.Second)
			w.Eval("console.log('test');")
		}
	}()
	w.Run()
}

I'm also checking the error variable returned by the ExecuteScript vtable call and that says the script was executed successfully. Opening up the dev console indicates it's not getting excuted. Tried locking to main thread but that didn't work. Looking at my cgo version suggests we are doing all the right things in this call. I'm stumped!

How can I do js binding

I've the below:

package main

import (
	"fmt"
	"log"
	"net/http"
	"os"
	"path/filepath"
	"strings"
	"time"

	"github.com/jchv/go-webview2" // go install github.com/jchv/go-webview2@latest
)

func main() {
	w := webview2.NewWithOptions(webview2.WebViewOptions{
		Window:    nil,
		Debug:     false,
		DataPath:  "",
		AutoFocus: true,
		WindowOptions: webview2.WindowOptions{
			Title:  "Minimal webview example",
			Width:  800,
			Height: 600,
			IconId: 2,
			Center: true},
	})
	if w == nil {
		log.Fatalln("Failed to load webview.")
	}
	defer w.Destroy()

	http.HandleFunc("/", index)

	go http.ListenAndServe(":1234", nil)

	/*	w.Init("alert('hi')")
		w.Bind("ps", printSomething)
		w.SetTitle("Golang WebView 2 example")
		w.SetSize(800, 600, webview2.HintFixed)
		w.Navigate("http://localhost:1234/")
	*/
	// The window will be displayed once and then resized to this size.
	w.SetSize(600, 600, webview2.HintNone)
	// load a local HTML file.
	c, err := os.Getwd()
	if err != nil {
		log.Fatalln(err.Error())
	}
	w.Navigate(filepath.Join(c, "templates/index.html"))

	w.Bind("ps", printSomething)

	w.Run()
}

func index(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("Hello"))
}

func printSomething(name string) {
	now := time.Now().Format(time.Stamp)
	fmt.Println(textMessage(name, now))
	// w.Eval(fmt.Sprintf("setDivContent('output', '%s')", htmlMessage(name, now)))
}

func textMessage(name, time string) string {
	return fmt.Sprintf(">>> [%s] Hello, %s.", time, name)
}

func htmlMessage(name, time string) string {
	escapedName := strings.ReplaceAll(name, "'", "&#39;")
	return fmt.Sprintf(`Hello, <b>%s</b>. The current time is <span class="blue">%s</span>. Check your console window for a message.`, escapedName, time)
}

And

<!DOCTYPE>
<html> 
  <head>
    <title>Hello World</title> 
  </head>

  <body> 
    <h1>Hello World</h1> 
  </body>
  <script>
      // how to call the printSomething function!!
  </script>
</html>

I want to define the printSomething function, but did not know how to make it understand the webview in the gofunction, and did not know how to make it call it in the JS function!

Keyboard focus not set on browser by default

When creating a new webview in a new window, i.e. what the demo example does, keyboard focus is set on the overarching window, and not on the document object rendered by the webview. This means that keyboard access is not available. To reproduce:

  1. Run the demo app.
  2. Wait for the Wikipedia page to render.
  3. Press Tab.

Expected result: keyboard focus will be handled by the webview, and move through the focusable elements on the page.

Actual result: nothing happens.

This is a significant issue for accessibility. Not only does it prevent keyboard-only users accessing apps built with this library (or ones based on it), it also means that screen reader software is unable to access the webview's content, unless the user can work out how to manually set focus on the document (e.g. using the Win32 API).

SetSize //todo

go-webview2/webview.go

Lines 443 to 445 in 675e3b9

func (w *webview) SetSize(width int, height int, hint Hint) {
// TODO
}

Any plans on implementing this? I use go-webview2 exclusively for windows as it works much better than webview/webiew and not being able to control minimum window size via HintMin causes some issues :D

RPC_E_CHANGED_MODE (0x80010106) Error

I'm experimenting with Wails and used some simple Go code that queries some hardware settings. When doing so, I get an RPC_E_CHANGED_MODE error. I think this is related to how the WebView2 COM instance is created.

Any idea how and where to best fix this?

  • In WebView2
  • in Wails and how it's using WebView2
  • In the hardware querying package

infinite recursive call

I've added the flowing functions to chromium.go:

func (e *Chromium) GetDefaultBackgroundColor() (*COREWEBVIEW2_COLOR, error) {
	return e.controller.GetICoreWebView2Controller2().GetDefaultBackgroundColor()
}

func (e *Chromium) PutDefaultBackgroundColor(backgroundColor COREWEBVIEW2_COLOR) error {
	return e.controller.GetICoreWebView2Controller2().PutDefaultBackgroundColor(backgroundColor)
}

now on the lines with where .AddRef() is called i get the warning: "infinite recursive call"

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.