[Unrelated] Weird problem with fetch()/promise chaining

Ask for help about NoScript, no registration needed to post
User avatar
ZeroUnderscoreOu
Posts: 15
Joined: Sat Aug 26, 2017 1:19 am
Contact:

[Unrelated] Weird problem with fetch()/promise chaining

Post by ZeroUnderscoreOu »

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.

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);
});
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:

Code: Select all

fetch(Link).then((Data)=>{
    Data.text().then((Data)=>{
        console.log("Log",Data.length);
    })
});
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.
0_o
Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0
barbaz
Senior Member
Posts: 11064
Joined: Sat Aug 03, 2013 5:45 pm

Re: Weird problem with fetch()/promise chaining

Post by barbaz »

I don't recall the first way ever working for me.
*Always* check the changelogs BEFORE updating that important software!
-
User avatar
ZeroUnderscoreOu
Posts: 15
Joined: Sat Aug 26, 2017 1:19 am
Contact:

Re: Weird problem with fetch()/promise chaining

Post by ZeroUnderscoreOu »

It does for me (with scripts allowed):
Image
And you reminded me about another strange thing I forgot to mention: both with code pasted into console and run as a userscript it shows the log message as if it came from global.js. Though it may be caused by some library used on Imgur.
0_o
Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0
barbaz
Senior Member
Posts: 11064
Joined: Sat Aug 03, 2013 5:45 pm

Re: Weird problem with fetch()/promise chaining

Post by barbaz »

Checked again, it does work both ways with scripts enabled. But I don't get it working either way with scripts disabled. I'm using the Web Console for testing.

I tested in a clean profile without NoScript, and setting about:config > javascript.enabled to false produced the same results. So this is not a NoScript issue.
*Always* check the changelogs BEFORE updating that important software!
-
User avatar
ZeroUnderscoreOu
Posts: 15
Joined: Sat Aug 26, 2017 1:19 am
Contact:

Re: Weird problem with fetch()/promise chaining

Post by ZeroUnderscoreOu »

barbaz wrote:So this is not a NoScript issue.
Yeah, looks like.
Checked myself the same way (didn't know about script preference) and FF's behavior seems really counterintuitive to me. But I guess it's a thing to complain to Mozilla instead.
Tnx.
0_o
Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0
Post Reply