[Unrelated] Weird problem with fetch()/promise chaining
Posted: Sat Aug 26, 2017 2:34 am
I'm not sure if this is a problem from the last update, but I do think this is related to NoScript.
I noticed it while writing a small userscript for Imgur, so the code I quote assumes an image album open (imgur.com/a/*, imgur.com/gallery/*) and is run in Greasemonkey.
It runs as I expect it to while base domain (Imgur itself) is allowed. When it's not, script silently fails without any messages in page/browser consoles. Now, the interesting part is that if I change the code a bit, it starts working:
Second then() is put right after text() instead of being chained outside and parentheses are replaced with braces.
There might be some stupid mistake from me, but the inconsistency makes me think this is a thing with NoScript (including the partial blocking of code pasted into page console, but it might be a different topic).
Win 7 x64, FF 55.0.3 x64, NoScript 5.0.9, Greasemonkey 3.11.
I noticed it while writing a small userscript for Imgur, so the code I quote assumes an image album open (imgur.com/a/*, imgur.com/gallery/*) and is run in Greasemonkey.
Code: Select all
var Hash = document.location.pathname.match(/(gallery|a)\/(\w+)/)[2];
var Link = `${document.location.origin}/ajaxalbums/getimages/$Hash/hit.json`;
fetch(Link).then((Data)=>(Data.text())).then((Data)=>{
console.log("Log",Data.length);
});
Code: Select all
fetch(Link).then((Data)=>{
Data.text().then((Data)=>{
console.log("Log",Data.length);
})
});
There might be some stupid mistake from me, but the inconsistency makes me think this is a thing with NoScript (including the partial blocking of code pasted into page console, but it might be a different topic).
Win 7 x64, FF 55.0.3 x64, NoScript 5.0.9, Greasemonkey 3.11.