Firefox触发来自IAsyncEnumerable Core MVC控制器方法的WebSocket错误。

huangapple go评论78阅读模式
英文:

Firefox triggers Websocket error from IAsyncEnumerable Core MVC controller method

问题

I understand your instructions. Here's the translated content:

我正在使用可取消的Javascript Fetch来获取一个C# Microsoft.AspNet.WebApi.Core的IAsyncEnumerable控制器方法。在Chrome或Edge中没有错误,但Firefox记录如下:-

我不知道将HTTP Fetch转换为用于流式传输的Websocket是否符合W3C标准,或者微软是如何嵌入它的Browser-Link病毒的 Firefox触发来自IAsyncEnumerable Core MVC控制器方法的WebSocket错误。

这是普通的.html文件,不是.cshtml或Razor页面。

有人能解释发生了什么吗?

以下是JS代码: -

<script type="application/javascript">

async function doit()
{
      const decoder = new TextDecoder();

      const abortControl = new AbortController();
      const signal = abortControl.signal;
      setTimeout(() =>
        {
            abortControl.abort();
            console.log("*ABORTED*")
        }, 2000); // 模拟2秒后取消

      const fetchOpts = {signal:signal, method:'GET', cache:"no-cache"};
      const response = await fetch("https://localhost:7196/data/yieldfamilyname?inname=made", fetchOpts);
      const reader = response.body.getReader();

      let result = await reader.read();

      while (!result.done && !signal.aborted)
      {
            var personText = decoder.decode(result.value).replace(/\[|]/g, '').replace(/^,/, '');
            var person = JSON.parse(personText);
            console.log("chunk is", person.familyName);

            try {
                result = await reader.read();
            }
            catch (err) {
                console.log(err.message);
                break;
            }
      }
      reader.releaseLock();
}

doit()
</script>

在第一个Yield之后,这些消息被记录: -

chunk is MADE fred.html:32:14

使用Mutation Events已被弃用。请改用MutationObserver。browserLink:3299:5701

工具扩展已连接browserLink:50:1248

初始化工具服务... browserLink:50:1248

初始化工具设计表面服务browserLink:50:1248

初始化工具选择服务browserLink:50:1248

初始化工具标签导航服务browserLink:50:1248

初始化工具热键管理器服务browserLink:50:1248

主机扩展已连接browserLink:50:1248

初始化主机服务... browserLink:50:1248

chunk is MADEBGWE fred.html:32:14

Firefox无法与服务器建立连接wss://localhost:44312/ChunkIt/。
aspnetcore-browser-refresh.js:234:24

WebSocket连接失败。aspnetcore-browser-refresh.js:18:15

chunk is . . . .

ABORTED fred.html:19:14

操作已被中止。fred.html:38:15

英文:

I am using a cancellable Javascript Fetch to retrieve a C# Microsoft.AspNet.WebApi.Core IAsyncEnumerable Controller method. There is no error with Chrome or Edge but Firefox logs the following: -

Firefox触发来自IAsyncEnumerable Core MVC控制器方法的WebSocket错误。

I don't know if it is a W3C standard to convert a HTTP Fetch into a Websocket for Streaming or how Microsoft manages to embed it's Browser-Link virus Firefox触发来自IAsyncEnumerable Core MVC控制器方法的WebSocket错误。

Firefox触发来自IAsyncEnumerable Core MVC控制器方法的WebSocket错误。

This is plain .html not .cshtml or Razor pages.

Can anyone shed light on what's happening?

Here's the JS code: -

	&lt;script type=&quot;application/javascript&quot;&gt;

	async function doit()
	{
		  const decoder = new TextDecoder();

		  const abortControl = new AbortController();
		  const signal = abortControl.signal;
		  setTimeout(() =&gt;
			{
				abortControl.abort();
				console.log(&quot;*ABORTED*&quot;)
			}, 2000); // Simulate a cancel after 2 secs

		  const fetchOpts = {signal:signal, method:&#39;GET&#39;, cache:&quot;no-cache&quot;};
		  const response = await fetch(&quot;https://localhost:7196/data/yieldfamilyname?inname=made&quot;, fetchOpts);
		  const reader = response.body.getReader();

		  let result = await reader.read();

		  while (!result.done &amp;&amp; !signal.aborted)
		  {
				var personText = decoder.decode(result.value).replace(/\[|]/g, &#39;&#39;).replace(/^,/, &#39;&#39;);
				var person = JSON.parse(personText);
				console.log(&quot;chunk is&quot;, person.familyName);

				try {
					result = await reader.read();
				}
				catch (err) {
					console.log(err.message);
					break;
				}
		  }
		  reader.releaseLock();
	}

	doit()
&lt;/script&gt;

After the first Yield these messages are logged: -

chunk is MADE fred.html:32:14

Use of Mutation Events is deprecated. Use MutationObserver instead. browserLink:3299:5701

Tools extension connected browserLink:50:1248

Initializing tools services... browserLink:50:1248

Initializing tools design surface service browserLink:50:1248

Initializing tools selection service browserLink:50:1248

Initializing tools tag navigation service browserLink:50:1248

Initializing tools hotkey manager service browserLink:50:1248

Host extension connected browserLink:50:1248

Initializing host services... browserLink:50:1248

chunk is MADEBGWE fred.html:32:14

Firefox can’t establish a connection to the server at wss://localhost:44312/ChunkIt/.
aspnetcore-browser-refresh.js:234:24

WebSocket failed to connect. aspnetcore-browser-refresh.js:18:15

chunk is . . . .

ABORTED fred.html:19:14

The operation was aborted. fred.html:38:15

答案1

得分: 0

我在这里找到了答案。

看起来恶意脚本注入问题如此普遍,以至于.NET搜索所有提供的内容以寻找结束</body>标签。我以前的代码使用document.write来报告错误,现在已经被转换成了以下一行:

topWindow.write('&lt;p style=&quot;color:red&quot;&gt;' + message + '&quot;&lt;/p&gt;&lt;script src=&quot;/_framework/aspnetcore-browser-refresh.js&quot;&gt;&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;&quot;');

如果它不是语法无效,我可能不会知道:-(

英文:

I found the answer here

It appears the insidious script injection is so omni-present and all pervasive that .NET searches all served up content looking for an end-body tag. My old code that used document.write to report an error had one line converted to: -

topWindow.write(&#39;&lt;p style=&quot;color:red&quot;&gt;&#39; + message + &quot;&lt;/p&gt;&lt;script src=&quot;/_framework/aspnetcore-browser-refresh.js&quot;&gt;&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;&quot;);

If it wasn't syntactically invalid, I probably wouldn't have known Firefox触发来自IAsyncEnumerable Core MVC控制器方法的WebSocket错误。

huangapple
  • 本文由 发表于 2023年5月22日 15:55:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76304068.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定