Closed
Bug 1470656
Opened 7 years ago
Closed 7 years ago
Web extension using fetch() with CORS return NetworkError while executed inside a content_script
Categories
(WebExtensions :: Request Handling, defect)
Tracking
(Not tracked)
RESOLVED
INVALID
People
(Reporter: claudio.vallesi, Unassigned)
Details
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36
Steps to reproduce:
I'm writing an addon for a small community that should improve the UI/UX experience. One of the feature is the ability to load and inject an external CSS and the addon will check periodically for updates.
To do so, every time the script run, I check against the timestamp of the last update and if enough time has passed, execute a fetch against the URL provided by the user, passing through CORS Anywhere.
Actual results:
Firefox return a generic error: TypeError: NetworkError when attempting to fetch resource.
Which, as far as I understand, is coming from fetch directly and it's intentionally generic.
Expected results:
I would expect that it manage to reach the external URL and retrieve the content as it does on Chrome 67.
The code can be found here: https://github.com/theCrius/tildes-extended/blob/features/autoupdate-css/src/scripts/custom-styles.js#L48
Here is the snippet:
const fetchList = customStyles.urls.map(url => fetch('https://cors-anywhere.herokuapp.com/' + url).then(res => res.text()));
Promise.all(fetchList)
.then(cssArray => {
customStyles.lastPull = new Date().getTime();
customStyles.source = cssArray.join('\r\n\r\n') +'\r\n\r\n'+ customStyles.localCss;
resolve(customStyles);
})
.catch(err => {
reject(err);
});
I should point out that the exact same logic is used in the options page and works without any issue. That's why I'm afraid it's something that has to do with the content_scripts more than fetch itself.
options.js: https://github.com/theCrius/tildes-extended/blob/features/autoupdate-css/src/scripts/options.js#L183
| Reporter | ||
Updated•7 years ago
|
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → INVALID
| Reporter | ||
Comment 1•7 years ago
|
||
Typo in the manifest.json:
"permissions": [
"tabs",
"storage",
"*://cors-anywhere.herokuapp.com.com/*",
[....]
],
Fixed with the right URL, everything seems to work.
Updated•7 years ago
|
Component: Untriaged → Request Handling
Product: Firefox → WebExtensions
You need to log in
before you can comment on or make changes to this bug.
Description
•