wails/v3/pkg/application/messageprocessor_browser.go
Andrey Pshenkin 561473d992
[V3] Refactor binding transport layer (#4702)
* custom transport initial

* transport codecs

* runtime set transport

* events transport

* clauded example

* bundled runtime

* wip: transport

* rework transports

* rework dialog responses

* cleanup

* cleanup

* improve error handling in HTTPTransport

* cleanup

* cleanup

* cleanup

* cleanup

* review changes

* review changes

* review changes

* review changes

* review changes

* review changes

* review changes

* move documentation to website docs

* update doc

* update changelog

* introduce JSClient method for transport for embedding JS part in transport

---------

Co-authored-by: Atterpac <Capretta.Michael@gmail.com>
Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
2025-12-07 22:19:12 +11:00

39 lines
912 B
Go

package application
import (
"github.com/pkg/browser"
"github.com/wailsapp/wails/v3/pkg/errs"
)
const (
BrowserOpenURL = 0
)
var browserMethodNames = map[int]string{
BrowserOpenURL: "OpenURL",
}
func (m *MessageProcessor) processBrowserMethod(req *RuntimeRequest) (any, error) {
switch req.Method {
case BrowserOpenURL:
url := req.Args.AsMap().String("url")
if url == nil {
return nil, errs.NewInvalidBrowserCallErrorf("missing argument 'url'")
}
sanitizedURL, err := ValidateAndSanitizeURL(*url)
if err != nil {
return nil, errs.WrapInvalidBrowserCallErrorf(err, "invalid URL")
}
err = browser.OpenURL(sanitizedURL)
if err != nil {
m.Error("OpenURL: invalid URL - %s", err.Error())
return nil, errs.WrapInvalidBrowserCallErrorf(err, "OpenURL failed")
}
return unit, nil
default:
return nil, errs.NewInvalidBrowserCallErrorf("unknown method: %d", req.Method)
}
}