Chrome 开发工具(网络选项卡)不反映中止的请求

发布于 2025-01-11 05:22:45 字数 582 浏览 2 评论 0原文

我正在使用 AbortController 来取消使用 fetch 发出的请求。当我调用 abort() 时,我确实看到我的 catch() 处理程序被调用(这意味着请求已被有效取消),但请求本身仍然从端点(根据 Chrome 的网络选项卡)。

我预计请求会被中止,这样就不会出现下载流量(假设在调用 abort() 时尚未下载实际数据)。

这是 AbortController 的预期行为吗?

作为一个附带问题:如果“是的,这是预期的行为,请求不会以阻止下载流量的方式中止”,是否有办法真正中止使用 fetch 发出的请求?

编辑:我正在测试 https://fetch-abort-demo.glitch.me Chrome 和 Safari,虽然 Safari 会用红色突出显示中止的请求,但 Chrome 不会。也许这只是一个 Chrome UI 错误?

I'm playing around with AbortController in order to cancel requests made with fetch. When I call abort() I do see my catch() handler being called (which means that the request was effectively canceled), but the request itself still retrieves the data from the endpoint (according to Chrome's network tab).

I was expecting the request to be aborted so that no download traffic would occur (assuming that the download of the actual data hasn't happened at the time the abort() is called).

Is this the expected behavior of AbortController?

As a side question: If "yes, that is the expected behavior, the request isn't aborted in a way to prevent download traffic", is there a way to actually abort a request made with fetch?

Edit: I'm testing https://fetch-abort-demo.glitch.me with Chrome and Safari, and while Safari does highlight with red the aborted request, Chrome doesn't. Maybe this is just a Chrome UI bug?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错々过的事 2025-01-18 05:22:45

是的,这是预期的行为。

假设你对我说,把你身后袋子里的所有坚果都给我。

我把所有的坚果一勺一勺地递给你,放在你袋子里。
当我把我的包倒进你的包里时,你改变了主意,把包扔在地板上,一言不发地走开了。

你曾经的包里还有坚果吗?是的,因为传输数据需要时间,并且数据是以块/数据包的形式逐段传送的。只有当所有数据包都传输完成后,传输才算完成。

您的请求已中止,但获取数据包已经进行了一段时间。您刚刚停止请求和接受数据包。

Yes, that is expected behaviour.

Say you say to me, give me all the nuts from that bag behind you.

I hand you all the nuts scoop by scoop in the bag you are having.
Having been halfway finished emptying my bag into yours, you change your mind, drop the bag on the floor and walk away without saying a word.

Are there still nuts in what was once your bag? Yes, because it takes time to transfer data, and data is delivered in chunks/packets, piece by piece. Only when all the packets are transferred is the transmission complete.

Your request was aborted, but it had been in progress for a while getting packets. You just stopped requesting and accepting packets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文