jchv / go-webview2 Goto Github PK
View Code? Open in Web Editor NEWWebView2 bindings for pure Go, without CGo, based on the webview/webview bindings.
License: Other
WebView2 bindings for pure Go, without CGo, based on the webview/webview bindings.
License: Other
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
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
Is there a way to customize the title bar icon?
I only have one way to remove the title icon (But based on a version of my fork a long time ago)
link
Please see details
Seems to have no working way of closing the window, if it's not from the user clicking on the X.
webview.Destroy()
should close the window
webview.Destroy()
has no implementation, so no way of closing the window
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
go func(){
...
callback(func(){
w.Eval(" alert('Hello from webview!'); ")
)
..
}
Looks like there are no access to filesystem from webview2 using go-webview2. It can be implemented using SetVirtualHostNameToFolderMapping.
First of all, thanks for the package, it's awesome!
I wasn't able to find a way to open a window InPrivate or Incognito, am I missing something?
If it's not implemented, I saw here that WebView2 now supports InPrivate mode via CoreWebView2ControllerOptions.IsInPrivateModeEnabled and I was wondering if there are any plans on implementing it or if it is even possible?
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?
It seems that w.Bind()
and w.Init()
don't work on the first page load.
A workaround is to reload the page.
I've reproduced the problem along with a workaround: https://github.com/rcambrj/webview2-bug
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
thanks @jchv
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.
I'm looking to make a small, reproducible example but am opening this issue preemptively as there's a lot of detail on the linked issue:
wailsapp/wails#1569
Crux of the issue is it seems CGO interferes with the way go-winloader works. I'll update as I get more details. Cheers!
please push a tag such as v1.0.0 or v0.1.0
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.
How to create and use the environmentCompletedHandle or envCompleted
Add methods to invoke the print API, especially the sillent printing methods.
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?
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.
I have setup a mainWindow with a childwindow and use the childWindow in NewWindow(true, childWindow)
. when running the app I get a blank window with no errors in console instead of a window with the browser integrated.
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.
I found a few bugs in GetInstalledVersion
in webviewloader
:
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).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
Is there an option to allow or an allow windows resizing?
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 do you get the response headers from a request?
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 ...
Add a simple option to WindowOptions to control ShowWindow parameter (SW_SHOW, SW_SHOWMAXIMIZED...)
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.
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 ?
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!
I use wails to transmit binary image streams, but I found that if I bind the method of transmitting binary, wails will automatically base64 encode the binary. Is there a more efficient method?
such as this:https://github.com/MicrosoftEdge/WebView2Feedback/blob/main/specs/SharedBuffer.md
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, "'", "'")
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!
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:
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).
Lines 443 to 445 in 675e3b9
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
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?
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"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.