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

wails dev 2.9.1 js->go cannot pass large parameters #3714

Open
superDingda opened this issue Aug 29, 2024 · 0 comments
Open

wails dev 2.9.1 js->go cannot pass large parameters #3714

superDingda opened this issue Aug 29, 2024 · 0 comments
Labels
Bug Something isn't working

Comments

@superDingda
Copy link

Description

wails dev
Must operate in the browser
JS calls the go method to pass in a large (1024kb+) parameter

JS -> go passes a large parameter (json string for example), which will appear. Your go function is not triggered. If you print the log, wail will print a similar error

{"level":"error","time":"2024-08-28T16:55:46.752+0800","file":"gui/wlog.go:50","msg":"","appName":"123","content":{"content":"unexpected end of JSON input"}} \This error is because json is not fully collected
{"level":"error","time":"2024-08-28T16:55:46.754+0800","file":"gui/wlog.go:50","msg":"","appName":"123","content":{"content":"Unknown message from front end: \This is the lower half of the json


Further printing the stack, I found the problem is:
internal\frontend\devserver\devserver.go:191

		for {
			if err := websocket.Message.Receive(c, &msg); err != nil {   
				break
			}
			// We do not support drag in browsers
			if msg == "drag" {
				continue
			}

			// Notify the other browsers of "EventEmit"
			if len(msg) > 2 && strings.HasPrefix(string(msg), "EE") {
				d.notifyExcludingSender([]byte(msg), c)
			}

			// Send the message to dispatch to the frontend
			result, err := d.dispatcher.ProcessMessage(string(msg), d)
			if err != nil {
				d.logger.Error(err.Error())            // 191
			}
			if result != "" {
				locker.Lock()
				if err = websocket.Message.Send(c, result); err != nil {
					locker.Unlock()
					break
				}
				locker.Unlock()
			}
		}
	}).ServeHTTP(c.Response(), c.Request())

Finally, I found the cause of the problem:
When js calls the go export function, the parameter is too large and is split (I can understand this), but why is it not a continuous websocket frame, but split into two independent frames?

To Reproduce

wails dev
Must operate in the browser
JS calls the go method to pass in a large (1024kb+) parameter

Expected behaviour

wails dev
Must operate in the browser
JS calls the go method to pass in a large (1024kb+) parameter

Screenshots

No response

Attempted Fixes

No response

System Details

win11+v2.9.1

Additional context

No response

@superDingda superDingda added the Bug Something isn't working label Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant