WebGL - InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable

Hi there,

I want to change the url in the browser, according to several buttonNames, once the buttons are pressed.

I try to change the url via javascript with this javascriptlibrary.

QueryHandler.jslib

var QueryHandler = {
    GetParam: function(){
    var level = "";
        var queryString = window.location.search.substring(1);
        var params = queryString.split("&");

        for (var i=0; i<params.length; i++) {
            var param = params*.split("=");*

if(param[0] == “level”){ level = param[1]; }
}

//send string to Unity
var buffer = _malloc(lengthBytesUTF8(level) + 1);
writeStringToMemory(level, buffer);
return buffer;
},
SetParam: function(param){
console.log(“window.location.search”);
window.location.search = “?level=” + Pointer_stringify(param);
}
};
mergeInto(LibraryManager.library, QueryHandler);

On the buttons i have this C# script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Runtime.InteropServices;

public class Url_manipulator : MonoBehaviour
{
[DllImport(“__Internal”)]
private static extern string GetParam();

[DllImport(“__Internal”)]
private static extern void SetParam(string str);

public string path;
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}

private void OnMouseDown()
{
SetParam(path);
}
}
It changes the Url perfectly fine, but the project unfortunatly restarts, so i see the loading screen and everything.
Also theres InvalidStateError in the mozilla console (same behaviour on chrome):
InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable
The script from “http://localhost:59540/TemplateData/UnityProgress.javascript” was loaded even though its MIME type (“”) is not a valid JavaScript MIME type.[Learn More] localhost:59540
The script from “http://localhost:59540/Build/UnityLoader.js” was loaded even though its MIME type (“”) is not a valid JavaScript MIME type.[Learn More] localhost:59540
Successfully compiled asm.js code (total compilation time 0ms)
UnityLoader.js
The script from “http://localhost:59540/TemplateData/responsive.javascript” was loaded even though its MIME type (“”) is not a valid JavaScript MIME type.[Learn More] localhost:59540
Responsive WebGL Template by SIMMER.io v2019.02.08 responsive.javascript:2:5
Available at: Responsive WebGL Template | GUI Tools | Unity Asset Store for free! responsive.javascript:3:5
Host your WebGL Game at SIMMER.io for free! responsive.javascript:4:5
You can reduce your startup time if you configure your web server to host .unityweb files using gzip compression. UnityLoader.js:3:8480
[UnityCache] ‘http://localhost:59540/Build/unity%20test.wasm.framework.unityweb’ successfully downloaded and stored in the indexedDB cache UnityLoader.js:4:11214
[UnityCache] ‘http://localhost:59540/Build/unity%20test.wasm.code.unityweb’ successfully downloaded and stored in the indexedDB cache UnityLoader.js:4:11214
[UnityCache] ‘http://localhost:59540/Build/unity%20test.data.unityweb’ successfully downloaded and stored in the indexedDB cache UnityLoader.js:4:11214
Loading player data from data.unity3d UnityLoader.js:4:9380
Initialize engine version: 2018.3.9f1 (947e1ea5aa8d) UnityLoader.js:4:9380
Creating WebGL 2.0 context. UnityLoader.js:4:9380
Renderer: Mozilla UnityLoader.js:4:9380
Vendor: Mozilla UnityLoader.js:4:9380
Version: OpenGL ES 3.0 (WebGL 2.0) UnityLoader.js:4:9380
GLES: 3 UnityLoader.js:4:9380
EXT_color_buffer_float GL_EXT_color_buffer_float EXT_texture_filter_anisotropic GL_EXT_texture_filter_anisotropic OES_texture_float_linear GL_OES_texture_float_linear WEBGL_compressed_texture_s3tc GL_WEBGL_compressed_texture_s3tc WEBGL_compressed_texture_s3tc_srgb GL_WEBGL_compressed_texture_s3tc_srgb WEBGL_debug_renderer_info GL_WEBGL_debug_renderer_info WEBGL_debug_shaders GL_WEBGL_debug_shaders WEBGL_lose_context GL_WEBGL_lose_context UnityLoader.js:4:9380
OPENGL LOG: Creating OpenGL ES 3.0 graphics device ; Context level <OpenGL ES 3.0> ; Context handle 1 UnityLoader.js:4:9380
WARNING: Shader Unsupported: ‘Standard’ - Pass ‘META’ has no vertex shader
UnityLoader.js:4:9380
UnloadTime: 0.000000 ms UnityLoader.js:4:9380
Use of the motion sensor is deprecated. 9d80b04b-1533-48a2-9bd1-f8f333642324:2:228360
Use of the orientation sensor is deprecated. 9d80b04b-1533-48a2-9bd1-f8f333642324:2:228360


Maybe someone is realy into this topic and help me ?! :slight_smile:

Which means that you can make iterables that are lazy. Calling the built-in next function on an object will attempt to call its next method prepaidgiftbalance.

They have created a QueryHandler.jslib file and a C# script called Url_manipulator, which changes the URL when a button is pressed. However, they are facing some issues. Whenever they change the URL, the project restarts and they see the loading screen. Additionally, they are receiving an “InvalidStateError” in the Mozilla console, which is causing the same behavior in Chrome. Furthermore, some scripts are being loaded, even though their MIME type is not a valid JavaScript MIME type- 1

It seems that the issue could be caused by the fact that changing the URL in the browser causes the page to reload, which restarts the Unity project. To prevent this from happening, the user could try to change the URL without causing a page reload. One way to achieve this is by using the HTML5 history API, which allows changing the URL without reloading the page. Additionally, the “InvalidStateError” could be caused by the fact that some scripts are being loaded with an invalid MIME type. The user could try to fix this by ensuring that the server is sending the correct MIME types for the scripts.

,They have created a QueryHandler.jslib file and a C# script called Url_manipulator, which changes the URL when a button is pressed. However, they are facing some issues. Whenever they change the URL, the project restarts and they see the loading screen. Additionally, they are receiving an “InvalidStateError” in the Mozilla console, which is causing the same behavior in Chrome. Furthermore, some scripts are being loaded, even though their MIME type is not a valid JavaScript MIME type- 1

It seems that the issue could be caused by the fact that changing the URL in the browser causes the page to reload, which restarts the Unity project. To prevent this from happening, the user could try to change the URL without causing a page reload. One way to achieve this is by using the HTML5 history API, which allows changing the URL without reloading the page. Additionally, the “InvalidStateError” could be caused by the fact that some scripts are being loaded with an invalid MIME type. The user could try to fix this by ensuring that the server is sending the correct MIME types for the scripts.