We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

Cross-global fetch usage

这篇翻译不完整。请帮忙从英语翻译这篇文章

本文解释了在fetch时发生的边缘情况(以及潜在的其他APIs展示相同类型的资源检索行为)。当从“iframe”发起包含相对url的跨源fetch时,相对url用于针对当前全局位置而不是iframe的位置进行解析。

边缘情况

大多数网站几乎不会遇到这种边缘情况。如下:

  • 需要一个同源的iframe
  • 该同源iframe需要具有不同基址位置
  • 必须使用跨全局的fetch函数, 例如. frame.contentWindow.fetch()
  • 传递给fetch函数的是相对url

遇到的问题

以前,我们从当前全局URL中解析相对URL,例如:

let absolute = new URL(relative, window.location.href)

This is not a problem as such. It is just that different APIs that exhibit this kind of behavior were doing it inconsistently in the beavior defined in the spec, which could lead to problems further down the line. 

解决方案

In Firefox 60 onwards, Mozilla resolves the relative URL against the global that owns the fetch() function being used (see bug 1432272).  So in the case described above, it is resolved against the iframe's location:

let absolute = new URL(relative, frame.contentWindow.location.href)

There is a lot of discussion in progress about getting new specs to align with this behavior change, to mitigate potential problems going forward.

文档标签和贡献者

此页面的贡献者: wynejan
最后编辑者: wynejan,