Skip to content

Commit

Permalink
Fixes history in Firefox containers + some small additional changes (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
chaptergy authored Jan 15, 2023
1 parent 185e85c commit 7955729
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions src/common/Messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,17 @@ class _Messaging {
response = ((await browser.runtime.sendMessage(message)) ?? null) as ReturnType<T>;
} 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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/Requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class _Requests {
if (!Shared.storage.options.grantCookies || !browser.cookies || !browser.webRequest) {
return;
}
const domainMatches = /https?:\/\/(?:www\.)?(?:.+?)(?<domain>\/.*)?$/.exec(request.url);
const domainMatches = /https?:\/\/(?:www\.)?(?<domain>.+?)(?:\/.*)?$/.exec(request.url);
if (!domainMatches?.groups) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/netflix/NetflixApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<NetflixHistoryItem[]> {
Expand Down

0 comments on commit 7955729

Please sign in to comment.