~eliasnaur/gio

60bed57cd7f4df2dfb9fb830ce33b198571bf07d — Elias Naur 5 days ago fc2a2ae
cmd/gogio: use URL query for passing arguments to wasm programs

The location.hash method doesn't work correctly with multiple
iframes and Safari.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
1 files changed, 5 insertions(+), 6 deletions(-)

M cmd/gogio/jsbuild.go
M cmd/gogio/jsbuild.go => cmd/gogio/jsbuild.go +5 -6
@@ 51,12 51,11 @@ func buildJS(bi *buildInfo) error {

			const go = new Go();

			// Pick up argv from location hash (#args).
			var hash = location.hash;
			if (hash.length > 0 && hash[0] == '#') {
				hash = decodeURIComponent(hash.substr(1));
				go.argv = hash.split(" ");
				go.argv.unshift("gio"); // os.Args(0)
			// Pick up argv from the argv query argument (if set).
			const params = new URLSearchParams(location.search);
			const argv = params.get("argv");
			if (argv) {
				go.argv = go.argv.concat(argv.split(" "));
			}

			WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {