webgl saving.

hi im making clicker in webgl to put it on kongrate I was trying to do sth like that but Is not working for me.

this is main script for clicking and etc.
public class dmg : MonoBehaviour {

	public GameDetails gd;
	public DataAccess data;
	public GameObject enemy;
	public GameObject liveenemy;
	public Text clicks;
	public Text DPC;
	public Text DPS;
	public Text CRIT;
	public Text CRITM;
	public Text lvl;
	public Button DPCup;
	public Button DPSup;
	public Button critup;
	public Button critmup;
	public Button nextlvl;
	public Button prevlvl;
	public float clickn;
	public float hp;
	public float money;
	public float bosshp;
	public float maxhp;
	public float dpc;
	public float dps;
	public float crit;
	public float critmultiply;
	public float crat;
	public float dpclvl =1;
	public float dpslvl=1;
	public float critlvl = 1;
	public  float critmultiplylvl=1;
	public Image hb;
	public Image hb2;
	public float enemykilled;
	public float bosskilled;
	public int bosskilledcount;
	public float stage=1;
	public float updpcprice =10;
	public float updpsprice=20;
	public float critupprice =40;
	public float critmultiplyprice = 80;
	bool bossspawned = false;
	bool enemyspawned = false;
	bool crithappend = false;
	// Use this for initialization
	void Start () {
		maxhp = maxhp +stage*100;
		hp = maxhp;
		bosshp = maxhp * 2;
		
	}

	
	void Update()
	{
		gd.bosshp = bosshp;
		gd.bosskilled = bosskilled;
		gd.bosskilledcount = bosskilledcount;
		gd.clickn = clickn;
		gd.crit = crit;
		gd.critlvl = critlvl;
		gd.critmultiply = critmultiply;
		gd.critmultiplylvl = critmultiplylvl;
		gd.critmultiplyprice = critmultiplyprice;
		gd.critupprice = critupprice;
		gd.dpc = dpc;
		gd.dpclvl = dpclvl;
		gd.dps = dps;
		gd.dpslvl = dpslvl;
		gd.enemykilled = enemykilled;
		gd.hp = hp;
		gd.maxhp = maxhp;
		gd.money = money;
		gd.stage = stage;
		gd.updpcprice = updpcprice;
		gd.updpsprice = updpsprice;
	


		hb2.rectTransform.sizeDelta = hb.rectTransform.sizeDelta;
		crat = UnityEngine.Random.Range(0.1f,100);
		if (crat <= crit * 100)
		{
			crithappend = true;
		}
		else
		{
			crithappend = false;
		}


[...]



	public void evas()//save
	{
		data.Save();
		
	}
	public void daol()//load
	{
		data.Load();

	}
}

Data acces

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

public class DataAccess : MonoBehaviour
{public dmg dmg;
	[DllImport("__Internal")]
	private static extern void SyncFiles();

	[DllImport("__Internal")]
	private static extern void WindowAlert(string message);

	public void Save()
	{
		
		string dataPath = string.Format("{0}/GameDetails.dat", Application.persistentDataPath);
		BinaryFormatter binaryFormatter = new BinaryFormatter();
		FileStream fileStream;

		try
		{
			if (File.Exists(dataPath))
			{
				File.WriteAllText(dataPath, string.Empty);
				fileStream = File.Open(dataPath, FileMode.Open);
			}
			else
			{
				fileStream = File.Create(dataPath);
			}

			binaryFormatter.Serialize(fileStream, dmg.gd);
			fileStream.Close();

			if (Application.platform == RuntimePlatform.WebGLPlayer)
			{
				SyncFiles();
			}
		}
		catch (Exception e)
		{
			PlatformSafeMessage("Failed to Save: " + e.Message);
		}
	}

	public GameDetails Load()
	{
		dmg.gd = null;
		string dataPath = string.Format("{0}/GameDetails.dat", Application.persistentDataPath);

		try
		{
			if (File.Exists(dataPath))
			{
				BinaryFormatter binaryFormatter = new BinaryFormatter();
				FileStream fileStream = File.Open(dataPath, FileMode.Open);

				dmg.gd= (GameDetails)binaryFormatter.Deserialize(fileStream);
				fileStream.Close();
			}
		}
		catch (Exception e)
		{
			PlatformSafeMessage("Failed to Load: " + e.Message);
		}

		return dmg.gd;
	}

	private static void PlatformSafeMessage(string message)
	{
		if (Application.platform == RuntimePlatform.WebGLPlayer)
		{
			WindowAlert(message);
		}
		else
		{
			Debug.Log(message);
		}
	}
}

HandleIO.jslib

var HandleIO = {
    WindowAlert : function(message)
    {
        window.alert(Pointer_stringify(message));
    },
    SyncFiles : function()
    {
        FS.syncfs(false,function (err) {
            // handle callback
        });
    }
};

mergeInto(LibraryManager.library, HandleIO);

GameDetails

using System;

[Serializable]
public class GameDetails
{

	public float clickn;
	public float hp;
	public float money;
	public float bosshp;
	public float maxhp;
	public float dpc;
	public float dps;
	public float crit;
	public float critmultiply;

	public float dpclvl;
	public float dpslvl;
	public float critlvl;
	public float critmultiplylvl;
	public float enemykilled;
	public float bosskilled;
	public int bosskilledcount;
	public float stage;
	public float updpcprice;
	public float updpsprice;
	public float critupprice;
	public float critmultiplyprice;

	
}

I have error on browser webgl build .

An error occurred running the Unity content on this page. See your browser JavaScript console for more info. The error was:
uncaught exception: abort(-1) at jsStackTrace (11.wasm.framework.unityweb:1559:13)
stackTrace (11.wasm.framework.unityweb:1576:12)
abort (11.wasm.framework.unityweb:16667:44)
_SyncFiles (11.wasm.framework.unityweb:9639:54)
wasm-function[273] (11.wasm.framework.unityweb:0:1)
wasm-function[32751] (11.wasm.framework.unityweb:10675757:1)
c95d9c1bfd7abcd5144cbf4c7557a6d1 [UnityLoader.c95d9c1bfd7abcd5144cbf4c7557a6d1/Module.dynCall_v] (11.wasm.framework.unityweb:16389:59)
invoke_v (11.wasm.framework.unityweb:15632:5)
wasm-function[32295] (11.wasm.framework.unityweb:10581192:1)
wasm-function[32307] (11.wasm.framework.unityweb:10588511:1)
wasm-function[26178] (11.wasm.framework.unityweb:9624294:1)
wasm-function[26361] (11.wasm.framework.unityweb:9643811:1)
wasm-function[26386] (11.wasm.framework.unityweb:9649110:1)
wasm-function[17364] (11.wasm.framework.unityweb:7679121:1)
wasm-function[17365] (11.wasm.framework.unityweb:7679148:1)
wasm-function[17172] (11.wasm.framework.unityweb:7644176:1)
wasm-function[17176] (11.wasm.framework.unityweb:7644659:1)
wasm-function[29352] (11.wasm.framework.unityweb:10036904:1)
wasm-function[32691] (11.wasm.framework.unityweb:10673878:1)
c95d9c1bfd7abcd5144cbf4c7557a6d1 [UnityLoader.c95d9c1bfd7abcd5144cbf4c7557a6d1/Module.dynCall_viiii] (11.wasm.framework.unityweb:16329:67)
invoke_viiii (11.wasm.framework.unityweb:15092:5)
wasm-function[25073] (11.wasm.framework.unityweb:9342907:1)
wasm-function[17318] (11.wasm.framework.unityweb:7669281:1)
wasm-function[17317] (11.wasm.framework.unityweb:7667770:1)
wasm-function[17312] (11.wasm.framework.unityweb:7665538:1)
wasm-function[17146] (11.wasm.framework.unityweb:7642370:1)
wasm-function[26967] (11.wasm.framework.unityweb:9705281:1)
wasm-function[32651] (11.wasm.framework.unityweb:10672538:1)
c95d9c1bfd7abcd5144cbf4c7557a6d1 [UnityLoader.c95d9c1bfd7abcd5144cbf4c7557a6d1/Module.dynCall_iiiii] (11.wasm.framework.unityweb:16289:67)
invoke_iiiii (11.wasm.framework.unityweb:14732:12)
wasm-function[30851] (11.wasm.framework.unityweb:10373994:1)
wasm-function[31164] (11.wasm.framework.unityweb:10416425:1)
wasm-function[2894] (11.wasm.framework.unityweb:1143602:1)
wasm-function[2888] (11.wasm.framework.unityweb:1142345:1)
wasm-function[7962] (11.wasm.framework.unityweb:3392002:1)
wasm-function[7946] (11.wasm.framework.unityweb:3386935:1)
wasm-function[9585] (11.wasm.framework.unityweb:4172744:1)
wasm-function[9584] (11.wasm.framework.unityweb:4172122:1)
wasm-function[8286] (11.wasm.framework.unityweb:3507341:1)
wasm-function[8084] (11.wasm.framework.unityweb:3436832:1)
wasm-function[8072] (11.wasm.framework.unityweb:3430255:1)
wasm-function[32751] (11.wasm.framework.unityweb:10675757:1)
c95d9c1bfd7abcd5144cbf4c7557a6d1 [UnityLoader.c95d9c1bfd7abcd5144cbf4c7557a6d1/Module.dynCall_v] (11.wasm.framework.unityweb:16389:59)
browserIterationFunc (11.wasm.framework.unityweb:8993:11)
runIter (11.wasm.framework.unityweb:8363:13)
Browser_mainLoop_runner (11.wasm.framework.unityweb:9048:9)

If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
using UnityEngine.UI;
public class DataToSav : MonoBehaviour {
[DllImport(“__Internal”)]
private static extern void SyncFiles();

[DllImport("__Internal")]
private static extern void WindowAlert(string message);
public Text txt;
public void OnMouseDown()
{
	savedData.buildingOne++;
}
private void Update()
{
	txt.text = savedData.buildingOne.ToString();
}
public void SaveStuff()
{

	BinaryFormatter bf = new BinaryFormatter();
	FileStream file = File.Create(Application.persistentDataPath + "save.dat");
	bf.Serialize(file, savedData);
	file.Close();
	if (Application.platform == RuntimePlatform.WebGLPlayer)
	{
		SyncFiles();
	}
}
public void LoadEverythingFromDisk()
{
	
	BinaryFormatter bf = new BinaryFormatter();
	FileStream file;
	if (File.Exists(Application.persistentDataPath + "save.dat"))
	{
		file = File.Open(Application.persistentDataPath + "save.dat", FileMode.Open);
		savedData = (DataToSave)bf.Deserialize(file);
		file.Close();
		
	}
	else
	{
	
		savedData.buildingOne = 0;
	
	}
}
[System.Serializable]
public class DataToSave
{
	[Header("buildings")]
	public int buildingOne;

	//etc
}

public DataToSave savedData;

}

and create folder in assets with path Assets/Plugins/WebGL/HandleIO.jslib

You can create HandleIo.jslib in notepad++

var HandleIO = {
    WindowAlert : function(message)
    {
        window.alert(Pointer_stringify(message));
    },
    SyncFiles : function()
    {
        FS.syncfs(false,function (err) {
            // handle callback
        });
    }
};

mergeInto(LibraryManager.library, HandleIO);

and thats work