wails icon indicating copy to clipboard operation
wails copied to clipboard

wails dev 2.9.1 js->go cannot pass large parameters

Open superDingda opened this issue 1 year ago • 0 comments

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 avatar Aug 29 '24 09:08 superDingda