rafaelgomesxyz / esgst

An extension that enhances SteamGifts / SteamTrades.
MIT License
146 stars 23 forks source link

Make the extension compatible with Firefox Containers #482

Closed olloff closed 6 years ago

olloff commented 6 years ago

Hi again.

Remember me whining about ESGST userscript not working with Firefox Containers? Its good if you do, because I'm struggling to find that ticket. Anyway, you managed it to get work flawlessly. Now same issue is related to the Firefox extension.

ESGST extension can't enter GA's being used from a containerized steamgifts tab. It is possible to enter from GA page, but not from front page, see https://i.imgur.com/Id4FVC5.png

Browser: Firefox 60.0.a1 Extension: 7.14.2 Related log entries:

Error: WebExtension context not found!  ExtensionParent.jsm:853:13
SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data  esgst.js:13543:28
rafaelgomesxyz commented 6 years ago

Weird, the extension already uses credentials: include, which should take care of that. Did this start happening recently? Or are you using the extension for the first time?

olloff commented 6 years ago

Or are you using the extension for the first time?

I, actually, do. Sorry for not checking it before, I was waiting for some GreaseMonkey progress first.

First (7.7.3) version of you extension gave exact same result with Firefox 60.0.a1, but if you suppose browser regression (personally I doubt that's the case), I can do some more tests for you.

rafaelgomesxyz commented 6 years ago

I've been searching and haven't found a way to solve this.

olloff commented 6 years ago

@revilheart That's sad. What on your opinion can cause the bug? Is it related to webextensions or contextual identities (containers)? Can related changes be requested from Mozilla community?

rafaelgomesxyz commented 6 years ago

Actually I tried the same thing I did for the script, and after some testing I think it works. I'm not sure if cross-domain requests would be affected though, I guess I'd need to test that some other time. Do you want to test it?

olloff commented 6 years ago

Yeah, off course.

rafaelgomesxyz commented 6 years ago

I think it's related to the fact that both XHR and fetch are unable to detect cookies from the current container when requesting from the background page of extensions, so maybe it's something that Firefox has to fix. I did have a quick look at the contextualIdentities API for extensions, but I couldn't get it to work.

Do you know how to load a temporary add-on on Firefox? That's the only way you can test it, since I haven't released the version yet.

olloff commented 6 years ago

Do you know how to load a temporary add-on on Firefox?

I do.

On the first look 7.14.3 (Dev.13) works perfectly.

Luckz commented 6 years ago

Out of curiosity, if you can localise it, which change exactly fixed it?

rafaelgomesxyz commented 6 years ago

@Luckz All issues get closed with the commit that fixed them. So in this case, if you look at the commit linked to this issue (https://github.com/revilheart/ESGST/commit/19169359083a491eefaef02fbde9de0fe15d97dd) you will see what changed to fix it.

If you don't understand the changes in that commit, basically the extension has a background page which allows cross-domain requests to be made (for example, if a request needs to be made to Steam, usually that request would be blocked, since Steam is not in the same domain as SteamGifts, but if the request is made from the background page it's not blocked). But since SteamGifts is in the same domain as SteamGifts, there is no need to make requests to SteamGifts from the background page. So what I did was: if the request is being made to SteamGifts (for example, entering a giveaway) it's now sent from the page itself instead of the background page, which allows all cookies from that page to be sent with it. And that's why it works with Firefox containers. When the request is made from the background page it cannot know which container you're currently on, so it grabs the cookies from the default session (with no containers).

Hope I explained it well.