Fetch: Possibility to enforce polyfill

Created on 2 Jul 2015  路  5Comments  路  Source: github/fetch

Is there a possibillity to force the usage of the polyfill instead of the browser functionality?

Most helpful comment

I would have to agree that the polyfill should not be implementing functionality for forcing usage. You can easily force usage of any polyfill in other ways. I recently had to get around a bug in MS Edge fetch implementation where it wasn't handling 401 responses correctly. My solution was just to unset window.fetch for MS Edge. After that, the polyfill worked as expected and set window.fetch to the polyfill version.

In the first <script> tag of the <head> section

if (navigator.userAgent.indexOf('Edge') !== -1) {
  window.fetch = undefined;
}

as long as that is executed before the fetch polyfill code, you're golden.

All 5 comments

No, the polyfill cannot be forced to override native browser behavior. See #147 and #162 for more discussion.

This would be a very nice feature to have available somehow, even if it meant digging deep into internals. We are seeing non-spec-compliant behavior from Edge, such as #407 and missing request bodies on DELETE. For now we will simply fork.

Native fetch also don't have support for response.body which the polyfill soon dose (once #404 gets accepted), So I agree that it would be useful to enforce the polyfill in browser that partially support fetch.

I understand that the team doesn't want to introduce a build process or otherwise complicate this module, but given that we've now seen our first fundamentally broken fetch() implementation in the wild, it may be necessary.

I don't believe it's going to be possible to easily test for the broken PUT/PATCH/DELETE Content-Length functionality, so it would be really nice to have a UMD shim introduced.

I would have to agree that the polyfill should not be implementing functionality for forcing usage. You can easily force usage of any polyfill in other ways. I recently had to get around a bug in MS Edge fetch implementation where it wasn't handling 401 responses correctly. My solution was just to unset window.fetch for MS Edge. After that, the polyfill worked as expected and set window.fetch to the polyfill version.

In the first <script> tag of the <head> section

if (navigator.userAgent.indexOf('Edge') !== -1) {
  window.fetch = undefined;
}

as long as that is executed before the fetch polyfill code, you're golden.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AllenFang picture AllenFang  路  5Comments

poppinlp picture poppinlp  路  4Comments

hannesvdvreken picture hannesvdvreken  路  4Comments

xgqfrms-GitHub picture xgqfrms-GitHub  路  4Comments

huanghaiyang picture huanghaiyang  路  3Comments