From 7955729f4e7bccc681dc00dfe2cf44054e728db5 Mon Sep 17 00:00:00 2001 From: chaptergy Date: Sun, 15 Jan 2023 16:16:55 +0100 Subject: [PATCH] Fixes history in Firefox containers + some small additional changes (#253) * Expands readme development section to include setting an addon id * Fallback in Messaging error handling in case error is not in JSON format * Only set Netflix session as activated if profile name exists * Fixes domain regex for cookie fetching * Converts Netflix session check to optional chaining with nullish comparison --- README.md | 2 +- src/common/Messaging.ts | 18 +++++++++++------- src/common/Requests.ts | 2 +- src/services/netflix/NetflixApi.ts | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0ba686f5..9c804206 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ Never delete the `translations` branch after merging PRs from Crowdin, as Crowdi 1. Create an application in the [Trakt API](https://trakt.tv/oauth/applications/new) (don't forget to check the `/scrobble` permission). 2. In `Redirect uri:`, put `https://trakt.tv/apps`. 3. In `Javascript (cors) origins:`, put `moz-extension://` and `chrome-extension://`. -4. Copy the `.env.example` example file and change the Trakt.tv credentials. +4. Copy the `.env.example` example file and change the Trakt.tv credentials. Make sure to also set the extension ID to an arbitrary but unique string, otherwise some browser features might not be available to the extension. ```bash cp .env.example .env diff --git a/src/common/Messaging.ts b/src/common/Messaging.ts index c68b1c7b..4646a8ba 100644 --- a/src/common/Messaging.ts +++ b/src/common/Messaging.ts @@ -241,13 +241,17 @@ class _Messaging { response = ((await browser.runtime.sendMessage(message)) ?? null) as ReturnType; } catch (err) { if (err instanceof Error) { - const messagingError = JSON.parse(err.message) as MessagingError; - switch (messagingError.instance) { - case 'Error': - throw new Error(messagingError.data.message); - - case 'RequestError': - throw new RequestError(messagingError.data); + try { + const messagingError = JSON.parse(err.message) as MessagingError; + switch (messagingError.instance) { + case 'Error': + throw new Error(messagingError.data.message); + + case 'RequestError': + throw new RequestError(messagingError.data); + } + } catch (_) { + throw err; } } } diff --git a/src/common/Requests.ts b/src/common/Requests.ts index d431a932..3db75761 100644 --- a/src/common/Requests.ts +++ b/src/common/Requests.ts @@ -150,7 +150,7 @@ class _Requests { if (!Shared.storage.options.grantCookies || !browser.cookies || !browser.webRequest) { return; } - const domainMatches = /https?:\/\/(?:www\.)?(?:.+?)(?\/.*)?$/.exec(request.url); + const domainMatches = /https?:\/\/(?:www\.)?(?.+?)(?:\/.*)?$/.exec(request.url); if (!domainMatches?.groups) { return; } diff --git a/src/services/netflix/NetflixApi.ts b/src/services/netflix/NetflixApi.ts index f57bc2be..26c99366 100644 --- a/src/services/netflix/NetflixApi.ts +++ b/src/services/netflix/NetflixApi.ts @@ -188,7 +188,7 @@ class _NetflixApi extends ServiceApi { }); this.session = this.extractSession(responseText); } - if (this.session) { + if (this.session?.profileName != null) { this.isActivated = true; } } catch (err) { @@ -203,7 +203,7 @@ class _NetflixApi extends ServiceApi { if (!this.isActivated) { await this.activate(); } - return !!this.session && this.session.profileName !== null; + return this.session?.profileName != null; } async loadHistoryItems(): Promise {