Mouse won't unlock in WebGL build but does in the editor

I’m using this code: (in an Update function)

if (Input.GetKeyDown (KeyCode.Escape)) {
	unlock = true;
}

if (unlock) {
	Cursor.lockState = CursorLockMode.None;
	Cursor.visible = true;
	Screen.fullScreen = false;
} else {
	Cursor.lockState = CursorLockMode.Locked;
	Cursor.visible = false;
}

if (Input.GetMouseButtonDown (0)) {
	unlock = false;
} 

In the editor, it works as expected. For whatever reason though, in the actual WebGL Build, the cursor does not unlock. I’ve searched thru every script in my project, this is the only code affecting the mouse lock, so I’m confused as to why the mouse won’t unlock. Could someone help me out please?

Edit: I tried building the project as a standalone app, and it works perfectly. This leads me to believe it is a bug with WebGL, has anyone else come across this bug and figured out how to fix it? I need this app to be able to work on webpages.

Do not lock the cursor every frame. I would guess that you simply can’t detect the escape key as the escape key is already handled by the browser to automatically unlock the cursor. However since you re-lock the cursor everyframe you can’t unlock it…

So strictly speaking it’s not a bug but simply misusing of the API. However it shouldn’t be possible to completely lock out the user. So if you classify it as bug, it’s a bug in the browser implementation. The browser could require a user interaction after the esc button has been pressed before it allows to re-lock the cursor. What browser do you use?