Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/polyfills/fetch.js

Issue 29334701: Issue 3588 - Worked around fetch() API not supporting chrome-extension:// URLs on Chrome <47 (Closed)
Patch Set: Added missing semicolon Created Jan. 27, 2016, 1:05 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld