Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[windows] Go Native WebView2Loader - Feedback #2004

Closed
stffabi opened this issue Oct 21, 2022 · 14 comments
Closed

[windows] Go Native WebView2Loader - Feedback #2004

stffabi opened this issue Oct 21, 2022 · 14 comments
Labels
Enhancement New feature or request

Comments

@stffabi
Copy link
Collaborator

stffabi commented Oct 21, 2022

The WebView2Loader is an essential part of the WebView2 runtime while running Wails on Windows. The loader is distributed by Microsoft as a DLL and must be loaded in order to start and use the WebView2 Runtime. It provides helper functions to determine the current version installed or to use a fixed runtime.
In order to have a Go (Single-Binary) experience the WebView2Loader.dll is embedded in the final application binary and
loaded from memory when needed.

There are several drawbacks with this approach:

  • Some Anti-Virus software give a Wails Application a higher score or ban them, because the binary contains a DLL signed by Microsoft and also contains "Copyright by Microsoft" strings.
  • Windows does not have the possibility to load a DLL from memory but instead always needs the DLL to be on the filesystem.
    To overcome this problem currently an awesome project written by @jchv is used go-winloader, which makes it possible to load the library from memory.
    Some drawbacks of the loader are:

To overcome those drawbacks the Wails-Team started to implement a Go native WebView2Loader by porting the OpenWebView2Loader (also written by @jchv 😀) to Go. This new loader allows us to directly interact with the WebView2 runtime straight from Go without having to load another DLL into memory.

The new loader can be activated by adding exp_gowebview2loader to your build tags: wails build --tags exp_gowebview2loader.

The loader is currently experimental, nevertheless we feel it's in a state where people are invited to try it out and
actively use it.

Please let us know your feedback or problems when using the new loader in this issue. Please also include the output of wails doctor.

Tested

Windows Build Version Platform Notes Status
11 Home - 22H2 10.0.22621.521 arm64 arm64 build running native
11 Home - 22H2 10.0.22621.521 arm64 amd64 build running in emulation
11 Home - 22H2 10.0.22621.521 arm64 x86 build running in emulation
11 Home - 22H2 10.0.22621.674 amd64 Native build on AMD Ryzen

Status: Stable

Merged with #1974
Released with v2.3.0

@stffabi stffabi added the Enhancement New feature or request label Oct 21, 2022
@stffabi stffabi changed the title Go Native WebView2Loader - Feedback [windows] Go Native WebView2Loader - Feedback Oct 21, 2022
@stffabi stffabi added Enhancement New feature or request and removed Enhancement New feature or request labels Oct 21, 2022
@stffabi stffabi pinned this issue Oct 21, 2022
@stffabi stffabi unpinned this issue Oct 21, 2022
@leaanthony
Copy link
Member

Just pushed a small fix to master.

@leaanthony
Copy link
Member

Some stats:

Build Binary Size UPX Compressed
dll embedded 8181760 3124736
go native 8036352 3099136

@LonglyCode
Copy link

LonglyCode commented Nov 6, 2022

Nice Job! My team have a web app used WebRTC technology only on a local network without SSL. It's wonderful used wails let it like a desktop app. But we need enabled 'unsafely-treat-insecure-origin-as-secure' on webview2 and setting server's IP address automatic. Same as #1507 .

@steowens
Copy link

So I just tried it out and it's a HUGE improvement. I am now able to compile my wails app with sqlite and not have the compilation fail with the same kind of issue I reported here: golang/go#57455 (comment)

@ziveni
Copy link

ziveni commented Mar 15, 2023

windows11 专业版 22621.1413 编译的exe无法运行

@stffabi
Copy link
Collaborator Author

stffabi commented Mar 15, 2023

windows11 专业版 22621.1413 编译的exe无法运行

Just to make sure, did you test the old WebView2Loader by using -tags native_webview2loader?

@onedaycodes
Copy link

windows server 2016操作系统下运行已打包的exe运行提示
image
打包命令
wails build -clean -webview2=embed --tags exp_gowebview2loader
编译环境
OS | Windows 10 Home
Version | 2009 (Build: 19045)
ID | 22H2
Go Version | go1.18.3
Platform | windows
Architecture | amd64

Wails

Version | v2.4.1

Dependencies

Dependency | Package Name | Status | Version
WebView2 | N/A | Installed | 112.0.1722.48
npm | N/A | Installed | 8.11.0
*upx | N/A | Available |
*nsis | N/A | Available |

    • Optional Dependency

@stffabi
Copy link
Collaborator Author

stffabi commented Apr 17, 2023

@onedaycodes could you please elaborate what your issue is? This dialog is expected and normal behaviour if the WebView2 is not installed on the target machine where the application is executed.

@onedaycodes
Copy link

你能详细说明你的问题是什么吗?如果未在执行应用程序的目标计算机上安装 WebView2,则此对话框是预期和正常行为。
我的问题是我使用了-webview=embed参数 希望能将webview运行环境嵌入打包后的exe二进制文件中,在其他未安装webview 运行环境的系统下可以直接run

@stffabi
Copy link
Collaborator Author

stffabi commented Apr 17, 2023

你能详细说明你的问题是什么吗?如果未在执行应用程序的目标计算机上安装 WebView2,则此对话框是预期和正常行为。
我的问题是我使用了-webview=embed参数 希望能将webview运行环境嵌入打包后的exe二进制文件中,在其他未安装webview 运行环境的系统下可以直接run

That's expected behaviour, embed only embeds the bootstrapper for installation of the runtime see also here. It does not auto-install in the background without confirmation from the user.
If you want to bundle the WebView2 Runtime with your app you need to use Fixed Runtime but bundling and installing it into a folder needs to be done by yourself. Wails does not provide any help for that out of the box.

@ziveni
Copy link

ziveni commented Apr 20, 2023

"Whether using the old one or not, the content cannot be displayed."

@stffabi
Copy link
Collaborator Author

stffabi commented Apr 20, 2023

"Whether using the old one or not, the content cannot be displayed."

Could you please open a new specific issue with a reproduction guide? That would be awesome 🙏 .

This issue is only meant for feedbacks/issues with the new webview2loader, but it seems like in your case something else is the problem.

@stffabi
Copy link
Collaborator Author

stffabi commented May 22, 2023

The new WebView2Loader is in a stable state and feedback was overall good. So I'm going to close this issue. If someone encounters a problem with the new loader, please open a new issue with a detailed report.

@PaleGreenFILE
Copy link

hello i have problem when use the obfuscated flags , i have app can be write a file with data and can read it , the permission of file is set , but when use production mode with obfuscated when try to write file its working i see the file and data is done but the application not render the file , i have a card for display information and when card is created we have a function for read the file in dev mode is works but in prod is not displaying

      Wails Doctor          

Wails

Version | v2.8.0

System

┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
| OS | MacOS |
| Version | 14.4 |
| ID | 23E214 |
| Go Version | go1.22.1 |
| Platform | darwin |
| Architecture | arm64 |
| CPU | Apple M2 Pro |
| GPU | Chipset Model: Apple M2 Pro Type: GPU Bus: Built-In Total Number of Cores: 19 Vendor: Apple (0x106b) Metal Support: Metal 3 |
| Memory | 16GB |
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Dependencies

┌────────────────────────────────────────────────────────────────┐
| Dependency | Package Name | Status | Version |
| Xcode command line tools | N/A | Installed | 2406 |
| Nodejs | N/A | Installed | 21.7.0 |
| npm | N/A | Installed | 10.5.0 |
| *Xcode | N/A | Available | |
| *upx | N/A | Available | |
| *nsis | N/A | Installed | v3.09 |
└─────────────────── * - Optional Dependency ────────────────────┘

Diagnosis

Optional package(s) installation details:

SUCCESS Your system is ready for Wails development!
and here my function write and read // WriteAccountToFile writes the account information to a .dat file
func (a *App) WriteAccountToFile(name, login, password, serverIP, platform string) error {
// Define folder path
folderPath := filepath.Join(filepath.Dir(a.ExecutablePath), "AccountInfo")

// Create the folder if it doesn't exist
if err := os.MkdirAll(folderPath, 0777); err != nil {
	return fmt.Errorf("failed to create folder: %w", err)
}

// Construct the file path
filePath := filepath.Join(folderPath, "account.dat")

// Open the file in append mode, create it if it doesn't exist
file, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
	return fmt.Errorf("failed to open file for writing: %w", err)
}
defer file.Close()

// Write login, password, and serverIP to file, separated by commas and followed by a newline character
line := fmt.Sprintf("%s,%s,%s,%s,%s\n", name, login, password, serverIP, platform)
if _, err := file.WriteString(line); err != nil {
	return fmt.Errorf("failed to write to file: %w", err)
}

return nil

}

// Account represents the account information
type Account struct {
Name string
Login string
Password string
ServerIP string
Platform string
}

// ReadAccountsFromFile reads accounts from a .dat file in the AccountInfo folder and returns them as a slice
func (a *App) ReadAccountsFromFile() ([]Account, error) {
var accounts []Account

// Construct the file path
filePath := filepath.Join(filepath.Dir(a.ExecutablePath), "AccountInfo", "account.dat")

// Read the entire file content
content, err := os.ReadFile(filePath)
if err != nil {
	return nil, err
}

// Split the content by newline characters
lines := strings.Split(string(content), "\n")
for _, line := range lines {
	// Split the line by ',' to extract login, password, and serverIP
	parts := strings.Split(line, ",")
	if len(parts) == 5 {
		account := Account{
			Name:     parts[0],
			Login:    parts[1],
			Password: parts[2],
			ServerIP: parts[3],
			Platform: parts[4],
		}
		accounts = append(accounts, account)
	}
}

return accounts, nil

} thanks all for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants