You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working with Wails v3 (alpha.38) on Windows and have encountered an issue with how new windows are created from external web content.
The Problem:
In my application, I load an external webpage within a Wails window. When a user clicks a link on this page (e.g., <a href="..." target="_blank">), WebView2 automatically creates a new window.
This new, automatically-created window has two main problems in a production build (wails3 build):
It has the site favicon icon, not my application's icon.
The developer tools (DevTools) are enabled, which is not desirable for a production release.
My goal is to intercept this "new window" request and instead create a new, properly configured Wails window to display the content. This new window should have my app's icon and have DevTools disabled, just like the main window in a production build.
What I've tried:
I've discovered that this can be handled by listening to the NewWindowRequested event on the ICoreWebView2 interface. My plan was to:
Get the underlying ICoreWebView2 instance of my Wails window.
Add an event handler for NewWindowRequested.
In the handler, call args.PutHandled(true) to prevent the default behavior.
Get the target URI from the event arguments.
Use application.NewWindow() to create a new, controlled Wails window.
However, I've run into a roadblock trying to implement this. My attempts to create a COM event handler in Go using reflection to access the underlying webview have resulted in a cgo panic: panic: compileCallback: argument size is larger than uintptr. This seems to happen when the handler struct holds a pointer to my *application.App.
I also noticed that some Wails v3 options I found in examples, like WebviewCreating or a plugins/edge package, do not exist in my version (alpha.38). The only available low-level hook seems to be WindowsOptions.WndProcInterceptor.
My Question:
What is the correct, recommended way in Wails v3 (specifically around alpha.38 for Windows) to intercept window.open calls? How can I get access to the ICoreWebView2 instance to attach a NewWindowRequested event handler without running into the cgo compile callback issues?
Is there a simpler API I am missing, or is there a standard pattern for doing this via WndProcInterceptor?
Any guidance or examples would be greatly appreciated. Thank you
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I'm working with Wails v3 (alpha.38) on Windows and have encountered an issue with how new windows are created from external web content.
The Problem:
In my application, I load an external webpage within a Wails window. When a user clicks a link on this page (e.g.,
<a href="..." target="_blank">), WebView2 automatically creates a new window.This new, automatically-created window has two main problems in a production build (
wails3 build):My goal is to intercept this "new window" request and instead create a new, properly configured Wails window to display the content. This new window should have my app's icon and have DevTools disabled, just like the main window in a production build.
What I've tried:
I've discovered that this can be handled by listening to the
NewWindowRequestedevent on theICoreWebView2interface. My plan was to:ICoreWebView2instance of my Wails window.NewWindowRequested.args.PutHandled(true)to prevent the default behavior.application.NewWindow()to create a new, controlled Wails window.However, I've run into a roadblock trying to implement this. My attempts to create a COM event handler in Go using reflection to access the underlying webview have resulted in a
cgopanic:panic: compileCallback: argument size is larger than uintptr. This seems to happen when the handler struct holds a pointer to my*application.App.I also noticed that some Wails v3 options I found in examples, like
WebviewCreatingor aplugins/edgepackage, do not exist in my version (alpha.38). The only available low-level hook seems to beWindowsOptions.WndProcInterceptor.My Question:
What is the correct, recommended way in Wails v3 (specifically around alpha.38 for Windows) to intercept
window.opencalls? How can I get access to theICoreWebView2instance to attach aNewWindowRequestedevent handler without running into thecgocompile callback issues?Is there a simpler API I am missing, or is there a standard pattern for doing this via
WndProcInterceptor?Any guidance or examples would be greatly appreciated. Thank you
Beta Was this translation helpful? Give feedback.
All reactions