[WebGL] Base64 string passed from javascript contains invalid characters

Hello! In my WebGL project I want to implement a feature that lets players import/export their savefiles as base64 strings. Since getting proper copy/paste in WebGL is such a pain, I decided to deal with it using javascript’s prompt. My JS code

OnSaveExportPromptClick: function(arg){
		var tSavefile = prompt("Your savefile:", Pointer_stringify(arg));		
	},
OnSaveImportPromptClick: function(){		
		var tSavefile = prompt("Paste your savefile:", "test");
		if (tSavefile != null && tSavefile != "") {			    			
			gameInstance.SendMessage('GameManager', 'OnSaveGameImportResult', tSavefile);
		} 
	}

If I just grab the string from Export and paste it into Import, Debug.Log outputs the same string which was exported, but when I try

public void OnSaveGameImportResult(string arg){    		
		Debug.Log("Savefile:

" + arg);
var plainBytes = System.Convert.FromBase64String(arg);
}
I get System.FormatException: Invalid character found.
Any idea how to solve that?

EDIT: To clarify, I do the initial Base64 encoding in C# and pass already encoded string to OnSaveExportPromptClick. What I want to do is to be able to copy it from the prompt, paste it in the next prompt and send it back to C#, here is the code:

    [DllImport("__Internal")]
	private static extern void OnSaveExportPromptClick(string arg);
	[DllImport("__Internal")]
	private static extern string OnSaveImportPromptClick();

	public void OnSaveGameExport(){
		string rawSave = JsonUtility.ToJson(saveData);
		var plainBytes = System.Text.Encoding.ASCII.GetBytes(rawSave); // tried UTF8 here, same error
		string encodedString = System.Convert.ToBase64String(plainBytes);
		OnSaveExportPromptClick(encodedString);
	}

	public void OnSaveGameImport(){	
		OnSaveImportPromptClick();		
	}

	public void OnSaveGameImportResult(string arg){		
		Debug.Log("Savefile:

" + arg);
var plainBytes = System.Convert.FromBase64String(arg);
}

Pointer_stringify” does not generate a base64 encoded string but simply a “string” version of the data behind a pointer. The documentation does not really specify what that string will look like.

If you just google for how to convert data to base64 in javascript you will find a lot solutions like this, this, this or this