Skip to content

Commit

Permalink
feat(Session): Add fallback for session data retrieval (#490)
Browse files Browse the repository at this point in the history
* feat(Session): Add fallback for session data retrieval

Should have added this when we first implemented session data retrieval to be honest. It makes a request to YouTube's service worker and the data there can change or the request can just fail.

* chore: lint
  • Loading branch information
LuanRT authored Aug 28, 2023
1 parent 4862c35 commit 10c15bf
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/core/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,17 @@ export default class Session extends EventEmitterLike {
) {
let session_data: SessionData;

const session_args = { lang, location, time_zone: tz, device_category, client_name, enable_safety_mode, visitor_data };

if (generate_session_locally) {
session_data = this.#generateSessionData({ lang, location, time_zone: tz, device_category, client_name, enable_safety_mode, visitor_data });
session_data = this.#generateSessionData(session_args);
} else {
session_data = await this.#retrieveSessionData({ lang, location, time_zone: tz, device_category, client_name, enable_safety_mode, visitor_data }, fetch);
try {
// This can fail if the data changes or the request is blocked for some reason.
session_data = await this.#retrieveSessionData(session_args, fetch);
} catch (err) {
session_data = this.#generateSessionData(session_args);
}
}

return { ...session_data, account_index };
Expand Down

0 comments on commit 10c15bf

Please sign in to comment.