function connect(needsReload) {
	ws = new WebSocket(location.origin.replace('http', 'ws') + '/_hmr', 'hmr');
	function sendSocketMessage(msg) {
		ws.send(JSON.stringify(msg));
	}

	ws.addEventListener('open', () => {
		log(`Connected to server.`);
		if (needsReload) {
			location.reload();
		} else {
			queue.forEach(sendSocketMessage);
			queue = [];
		}
	});

	ws.addEventListener('message', handleMessage);
	ws.addEventListener('error', handleError);
}
@param {boolean} [needsReload] Force page to reload once it's connected
to the server.