Skip to content

Commit 51c9e8f

Browse files
committed
fix: properly handle page icon parsed from browser API (Firefox); resolve errors related to properties of undefined (Firefox)
Signed-off-by: Robert Goniszewski <robertgoniszewski@outlook.com>
1 parent 2c78e7b commit 51c9e8f

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "grimoire-companion",
33
"displayName": "grimoire companion",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"description": "Companion extension for Grimoire.",
66
"author": "Robert Goniszewski <robert@goniszewski.com>",
77
"scripts": {

src/popup.svelte

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,20 @@
5555
$: $updatedUrl = $currentTab.url;
5656
5757
async function onValidateGrimoireApiUrl() {
58-
if (!configuration.grimoireApiUrl) {
58+
if (!configuration?.grimoireApiUrl) {
5959
$status.isGrimoireApiReachable = false;
6060
6161
showToast.error('Grimoire API URL is empty!');
6262
}
6363
64-
const isGrimoireApiReachable = await validateGrimoireApiUrl(configuration.grimoireApiUrl).catch(
65-
(error) => {
66-
logger.error('onValidateGrimoireApiUrl', 'Error validating Grimoire API URL', error);
67-
showToast(`Grimoire API is ${isGrimoireApiReachable}!`);
64+
const isGrimoireApiReachable = await validateGrimoireApiUrl(
65+
configuration?.grimoireApiUrl
66+
).catch((error) => {
67+
logger.error('onValidateGrimoireApiUrl', 'Error validating Grimoire API URL', error);
68+
showToast(`Grimoire API is ${isGrimoireApiReachable}!`);
6869
69-
return false;
70-
}
71-
);
70+
return false;
71+
});
7272
7373
if ($status.isGrimoireApiReachable && !isGrimoireApiReachable) {
7474
showToast.error('Grimoire API is not reachable!');
@@ -99,7 +99,7 @@
9999
name: 'fetch-categories-tags',
100100
body: {
101101
token,
102-
grimoireApiUrl: configuration.grimoireApiUrl
102+
grimoireApiUrl: configuration?.grimoireApiUrl
103103
}
104104
});
105105
@@ -125,7 +125,10 @@
125125
126126
const theme = await storage.get('theme');
127127
token = await storage.get('token');
128-
configuration = await storage.get('configuration');
128+
configuration = (await storage.get('configuration')) || {
129+
grimoireApiUrl: '',
130+
saveScreenshot: false
131+
};
129132
130133
if (theme) {
131134
document.documentElement.setAttribute('data-theme', themes[theme]);
@@ -188,7 +191,7 @@
188191
$loading.isSigningIn = true;
189192
190193
const newToken = await handleSignIn(
191-
configuration.grimoireApiUrl,
194+
configuration?.grimoireApiUrl,
192195
$credentials.emailOrUsername,
193196
$credentials.password
194197
);
@@ -458,8 +461,8 @@
458461
onAddBookmark(
459462
$currentTab,
460463
token,
461-
configuration.grimoireApiUrl,
462-
configuration.saveScreenshot
464+
configuration?.grimoireApiUrl,
465+
configuration?.saveScreenshot
463466
)}
464467
disabled={$loading.isAddingBookmark && !$loading.justAddedBookmark}
465468
>

src/shared/handlers/on-add-bookmark.handler.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export async function onAddBookmark(
2727

2828
let screenshot: string = '';
2929

30+
const iconIsDataUrl = $currentTab.icon_url.startsWith('data:');
31+
3032
try {
3133
if (capturePageScreenshot) {
3234
await new Promise((resolve) => {
@@ -62,7 +64,7 @@ export async function onAddBookmark(
6264
logger.debug('onAddBookmark', 'Bookmark body', {
6365
url: $currentTab.url,
6466
title: $currentTab.title,
65-
icon_url: $currentTab.icon_url,
67+
icon_url: iconIsDataUrl ? '' : $currentTab.icon_url,
6668
main_image_url: $currentTab.mainImage,
6769
content_html: $currentTab.contentHtml,
6870
description: $currentTab.description,
@@ -71,7 +73,8 @@ export async function onAddBookmark(
7173
note: $currentTab.note,
7274
importance: $currentTab.importance,
7375
flagged: $currentTab.flagged,
74-
screenshot
76+
screenshot,
77+
...(iconIsDataUrl ? { icon: $currentTab.icon_url } : {})
7578
});
7679

7780
const response = await sendToBackground<
@@ -91,7 +94,7 @@ export async function onAddBookmark(
9194
bookmark: {
9295
url: $currentTab.url,
9396
title: $currentTab.title,
94-
icon_url: $currentTab.icon_url,
97+
icon_url: iconIsDataUrl ? '' : $currentTab.icon_url,
9598
main_image_url: $currentTab.mainImage,
9699
content_html: $currentTab.contentHtml,
97100
description: $currentTab.description,
@@ -100,7 +103,8 @@ export async function onAddBookmark(
100103
note: $currentTab.note,
101104
importance: $currentTab.importance,
102105
flagged: $currentTab.flagged,
103-
screenshot
106+
screenshot,
107+
...(iconIsDataUrl ? { icon: $currentTab.icon_url } : {})
104108
}
105109
}
106110
});

src/shared/types/add-bookmark.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type AddBookmarkRequestBody = {
1010
note?: string;
1111
main_image_url?: string;
1212
icon_url?: string;
13+
icon?: string;
1314
importance?: number;
1415
flagged?: boolean;
1516
category: string;

0 commit comments

Comments
 (0)