func initBeforeUnloadFn(cancelFunc context.CancelFunc, wg *sync.WaitGroup, global js.Value) {
	wg.Add(1)
	var fn js.Func
	fn = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
		// args[0].Call("preventDefault") // debug in other browsers
		// args[0].Set("returnValue", "") // debug in chromium
		cancelFunc()
		fn.Release()
		wg.Done()
		return nil
	})
	global.Call("addEventListener", "beforeunload", fn)
}
// initBeforeUnloadFn registers a function to cancel the context when the browser is about to close.
// This should trigger other dom functions to release.
initBeforeUnloadFn registers a function to cancel the context when the browser is about to close.
This should trigger other dom functions to release.
// initBeforeUnloadFn registers a function to cancel the context when the browser is about to close . // This should trigger other dom functions to release .
func initBeforeUnloadFn(cancelFunc context.CancelFunc, wg *sync.WaitGroup, global js.Value) {
	wg.Add(1)
	var fn js.Func
	fn = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
		cancelFunc()
		fn.Release()
		wg.Done()
		return nil
	})
	global.Call("addEventListener", "beforeunload", fn)
}
func initBeforeUnloadFn ( cancelFunc context . CancelFunc , wg * sync . WaitGroup , global js . Value ) { wg . Add ( 1 ) var fn js . Func fn = js . FuncOf ( func ( this js . Value , args [ ] js . Value ) interface { } { cancelFunc ( ) fn . Release ( ) wg . Done ( ) return nil } ) global . Call ( " " , " " , fn ) }
initBeforeUnloadFn registers a function to cancel the context when the browser is about to close.
initBeforeUnloadFn registers a function to cancel the context when the browser is about to close .
// args[0].Call("preventDefault") // debug in other browsers // args[0].Set("returnValue", "") // debug in chromium