Skip to content

Commit

Permalink
fix firefox crash due to functions getting added to usersettings object
Browse files Browse the repository at this point in the history
  • Loading branch information
mymindstorm committed May 26, 2024
1 parent 78d7129 commit a5ef095
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ export class UserSettings {

if (storageLocation === StorageLocation.Local) {
await chrome.storage[storageLocation].set({
UserSettings: UserSettings.items,
// JSON.parse(JSON.stringify()) strips functions (e.g. getItem, setItem, ...) which may have been added to the object.
// Without this, a crash may occur as chrome.storage throws an error when trying to serialize a function.
UserSettings: JSON.parse(JSON.stringify(UserSettings.items)),
});
} else {
const { syncableSettings, localSettings } = UserSettings.splitSettings(
Expand All @@ -129,10 +131,10 @@ export class UserSettings {

await Promise.all([
chrome.storage[StorageLocation.Local].set({
UserSettings: localSettings,
UserSettings: JSON.parse(JSON.stringify(localSettings)),
}),
chrome.storage[StorageLocation.Sync].set({
UserSettings: syncableSettings,
UserSettings: JSON.parse(JSON.stringify(syncableSettings)),
}),
]);
}
Expand Down

0 comments on commit a5ef095

Please sign in to comment.