Index: lib/polyfills/fetch.js |
=================================================================== |
--- a/lib/polyfills/fetch.js |
+++ b/lib/polyfills/fetch.js |
@@ -19,9 +19,6 @@ |
(function(global) |
{ |
- if ("fetch" in global) |
- return; |
- |
function Response(xhr) |
{ |
this._xhr = xhr; |
@@ -37,7 +34,7 @@ |
} |
}; |
- global.fetch = function(url) |
+ function fetch(url) |
{ |
return new Promise(function(resolve, reject) |
{ |
@@ -57,5 +54,22 @@ |
xhr.open("GET", url); |
xhr.send(); |
}); |
- }; |
+ } |
+ |
+ // While the Fetch API is natively supported since Chrome 42, before |
+ // Chrome 47 it failed to fetch files from within the extension bundle. |
+ // https://code.google.com/p/chromium/issues/detail?id=466876 |
+ var builtinFetch = global.fetch; |
+ if (builtinFetch) |
+ global.fetch = function(url, init) |
+ { |
+ return builtinFetch(url, init).catch(function(reason) |
+ { |
+ if (new URL(url, document.URL).protocol == "chrome-extension:") |
+ return fetch(url); |
+ throw reason; |
+ }); |
+ }; |
+ else |
+ global.fetch = fetch; |
})(this); |