英文:
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病毒的
这是普通的.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: -
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
This is plain .html not .cshtml or Razor pages.
Can anyone shed light on what's happening?
Here's the JS code: -
<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); // Simulate a cancel after 2 secs
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>
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('<p style="color:red">' + message + '"</p><script src="/_framework/aspnetcore-browser-refresh.js"></script></body></html>"');
如果它不是语法无效,我可能不会知道:-(
英文:
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('<p style="color:red">' + message + "</p><script src="/_framework/aspnetcore-browser-refresh.js"></script></body></html>");
If it wasn't syntactically invalid, I probably wouldn't have known
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论