Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textarea tag creates a textarea with a part of the live-server code injected in it, if the closing textarea tag is not present. #3057

Open
krishnasharmak05 opened this issue Dec 24, 2024 · 0 comments

Comments

@krishnasharmak05
Copy link

I'm submitting a...

[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  <!-- Please search GitHub for a similar issue or PR before submitting -->
[ ] Feature request
[ ] Documentation issue or request
[ ] Other: <!-- Please describe: -->

Current behavior

In the presence of an opening textarea tag, without a closing textarea tag, some code is injected into the text area by this extension. Here's the code injected into the text area:

    <body><!-- Code injected by live-server -->
<script>
	// <![CDATA[  <-- For SVG support
	if ('WebSocket' in window) {
		(function () {
			function refreshCSS() {
				var sheets = [].slice.call(document.getElementsByTagName("link"));
				var head = document.getElementsByTagName("head")[0];
				for (var i = 0; i < sheets.length; ++i) {
					var elem = sheets[i];
					var parent = elem.parentElement || head;
					parent.removeChild(elem);
					var rel = elem.rel;
					if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") {
						var url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, '');
						elem.href = url + (url.indexOf('?') >= 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf());
					}
					parent.appendChild(elem);
				}
			}
			var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';
			var address = protocol + window.location.host + window.location.pathname + '/ws';
			var socket = new WebSocket(address);
			socket.onmessage = function (msg) {
				if (msg.data == 'reload') window.location.reload();
				else if (msg.data == 'refreshcss') refreshCSS();
			};
			if (sessionStorage && !sessionStorage.getItem('IsThisFirstTime_Log_From_LiveServer')) {
				console.log('Live reload enabled.');
				sessionStorage.setItem('IsThisFirstTime_Log_From_LiveServer', true);
			}
		})();
	}
	else {
		console.error('Upgrade your browser. This Browser is NOT supported WebSocket for Live-Reloading.');
	}
	// ]]>
</script>
</body>
</html>

Here is a snippet of the HTML code that caused this error:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width:device-width, initial-scale:1.0">
    </head>
    <body>
        <textarea>
    </body>
</html>

If the closing textarea tag is added, then, upon reload, the code is no longer present.

Expected behavior

An empty textarea should be created, instead of one with code in it.

Environment

Browser:

- [x] Chrome (desktop) version 131.0.6778.205
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] IE version XX
- [x] Edge version 131.0.2903.112

For Tooling issues:

- Live Server: <!-- Check which version is installed --> 5.7.9
- Platform:  <!-- Mac, Linux, Windows --> Windows 11
- Visual Studio Code: <!-- `code --version` --> 
1.96.2
fabdb6a30b49f79a7aba0f2ad9df9b399473380f
x64

Others

I came across this bug while working on pure HTML. No CSS, no JavaScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant