Skip to content

[v1.38.x] Stop fetching scratch.mit.edu/csrf_token and more optimizations - #7647

Merged
WorldLanguages merged 6 commits into
ScratchAddons:v1.38.xfrom
WorldLanguages:csrf-token-requests
Jul 15, 2024
Merged

[v1.38.x] Stop fetching scratch.mit.edu/csrf_token and more optimizations#7647
WorldLanguages merged 6 commits into
ScratchAddons:v1.38.xfrom
WorldLanguages:csrf-token-requests

Conversation

@WorldLanguages

@WorldLanguages WorldLanguages commented Jul 15, 2024

Copy link
Copy Markdown
Member

Resolves #7646

Changes

Reason for changes

See PR description: #7646

@WorldLanguages WorldLanguages added priority: 2 High priority. Includes crashes, major bugs and important features scope: addon Related to one or multiple addons scope: core Related to the core script/extension workings scope: upstream Related to something we depend on (like Scratch, a library, or the browser) labels Jul 15, 2024
@WorldLanguages WorldLanguages self-assigned this Jul 15, 2024
@WorldLanguages WorldLanguages changed the title Stop fetching scratch.mit.edu/csrf_token [v1.38.x] Stop fetching scratch.mit.edu/csrf_token Jul 15, 2024
@WorldLanguages

WorldLanguages commented Jul 15, 2024

Copy link
Copy Markdown
Member Author

Relevant commits from 2022:

/csrf_token/ fetched by the background page:

Commit apple502j@a35c0a8

// Extensions are executed on the default store.
// To get the default store ID reliably, we need to set cookies ourselves.
// We can't just grab it from existing cookies because that'll break in case
// someone deletes cookies.
// The temporary cookie expires after 10 seconds but is removed anyway.

@apple502j Was browser.cookies.getAllCookieStores[0] not a thing back then? It appears to get the default store ID reliably.

/csrf_token/ fetched by the popup:

Commit apple502j@ee2aa38

I believe the PR intended to add incognito support to Scratch Messaging. In Firefox, you can check the messages of the incognito logged-in account through the popup.

WorldLanguages and others added 4 commits July 15, 2024 13:49
…chAddons#7505)

* Remove unnecessary `cleanCsInfoCache` alarm

* Fetch messages less often if user inactive

* Format code

---------

Co-authored-by: WorldLanguages <WorldLanguages@users.noreply.github.com>
Adds the "exact count for studios" option back, but instead of loading the count (which sends a large number of requests to Scratch) every time a studio page is opened, the user has to click the "100+" first.
@WorldLanguages WorldLanguages changed the title [v1.38.x] Stop fetching scratch.mit.edu/csrf_token [v1.38.x] Stop fetching scratch.mit.edu/csrf_token and more optimizations Jul 15, 2024
@WorldLanguages
WorldLanguages merged commit f19bf24 into ScratchAddons:v1.38.x Jul 15, 2024
WorldLanguages added a commit to WorldLanguages/ScratchAddons that referenced this pull request Jul 15, 2024
…ions (ScratchAddons#7647)

* Use getAllCookieStores() instead of fetching hack

* Call background alarms less often (`msg-count-badge` affected) (ScratchAddons#7505)

* Remove unnecessary `cleanCsInfoCache` alarm

* Fetch messages less often if user inactive

* Format code

---------

Co-authored-by: WorldLanguages <WorldLanguages@users.noreply.github.com>

* Popup doesn't really need to refetch cookies

---------

Co-authored-by: WorldLanguages <WorldLanguages@users.noreply.github.com>
Comment thread background/handle-auth.js
if (cookieStores.length === 0) throw "";
if (cookieStores.some((store) => store.id === CHROME_DEFAULT)) {
// Chrome
return CHROME_DEFAULT;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I forgot to set scratchAddons.cookieStoreId.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is very badly named :P

WorldLanguages added a commit that referenced this pull request Jul 31, 2024
…7650)

* [v1.38.x] Stop fetching scratch.mit.edu/csrf_token and more optimizations (#7647)

* Use getAllCookieStores() instead of fetching hack

* Call background alarms less often (`msg-count-badge` affected) (#7505)

* Remove unnecessary `cleanCsInfoCache` alarm

* Fetch messages less often if user inactive

* Format code

---------

Co-authored-by: WorldLanguages <WorldLanguages@users.noreply.github.com>

* Popup doesn't really need to refetch cookies

---------

Co-authored-by: WorldLanguages <WorldLanguages@users.noreply.github.com>

* Set value of `scratchAddons.cookieStoreId`

* Format code

* [v1.38.x] Send less requests to `scratch.mit.edu/session` etc. (#7666)

* Initial commit

* Format code

* Fix TODO: handle chrome.storage.session undefined

* Remove invalid TODO

* Remove console.log

* Background: only use cache on first time

* Revert canUseCachedSession

* exact-count addon changes (profiles)

* Change animated-thumb later

* Only call refreshFn once

* Use underscore for _requestFetchFn attr

* Remove outdated comment

* Do not reference isScratchGui variable

* Add code comment

* Fix execution order

---------

Co-authored-by: WorldLanguages <WorldLanguages@users.noreply.github.com>

---------

Co-authored-by: WorldLanguages <WorldLanguages@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: 2 High priority. Includes crashes, major bugs and important features scope: addon Related to one or multiple addons scope: core Related to the core script/extension workings scope: upstream Related to something we depend on (like Scratch, a library, or the browser)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants