@@ -2,11 +2,11 @@ import { storageSettings } from "../index.js";
22import { StorageKeys , type SessionManager } from "../types.js" ;
33import { splitString } from "../utils.js" ;
44
5- function getStorageValue ( key : string ) {
5+ function getStorageValue ( key : string ) : unknown | undefined {
66 return new Promise ( ( resolve , reject ) => {
77 chrome . storage . local . get ( [ key ] , function ( result ) {
88 if ( chrome . runtime . lastError ) {
9- reject ( chrome . runtime . lastError ) ;
9+ reject ( undefined ) ;
1010 } else {
1111 resolve ( result [ key ] ) ;
1212 }
@@ -37,11 +37,14 @@ export class ChromeStore<V = StorageKeys> implements SessionManager<V> {
3737 itemKey : V | StorageKeys ,
3838 itemValue : unknown ,
3939 ) : Promise < void > {
40+ // clear items first
41+ await this . removeSessionItem ( itemKey ) ;
42+
4043 if ( typeof itemValue === "string" ) {
4144 splitString ( itemValue , storageSettings . maxLength ) . forEach (
42- async ( _ , index ) => {
45+ async ( splitValue , index ) => {
4346 await chrome . storage . local . set ( {
44- [ `${ storageSettings . keyPrefix } ${ itemKey } ${ index } ` ] : itemValue ,
47+ [ `${ storageSettings . keyPrefix } ${ itemKey } ${ index } ` ] : splitValue ,
4548 } ) ;
4649 } ,
4750 ) ;
@@ -83,11 +86,11 @@ export class ChromeStore<V = StorageKeys> implements SessionManager<V> {
8386 // remove items from the chrome.storage
8487 let index = 0 ;
8588 while (
86- chrome . storage . local . get (
89+ ( await getStorageValue (
8790 `${ storageSettings . keyPrefix } ${ String ( itemKey ) } ${ index } ` ,
88- ) !== undefined
91+ ) ) !== undefined
8992 ) {
90- chrome . storage . local . remove (
93+ await chrome . storage . local . remove (
9194 `${ storageSettings . keyPrefix } ${ String ( itemKey ) } ${ index } ` ,
9295 ) ;
9396 index ++ ;
0 commit comments