| 11 | } |
| 12 | |
| 13 | class ExtCache implements CacheStorage { |
| 14 | get<T>(key: string): Promise<T | undefined> { |
| 15 | return new Promise((resolve) => { |
| 16 | chrome.storage.session.get(key, (value) => { |
| 17 | const lastError = chrome.runtime.lastError; |
| 18 | if (lastError) { |
| 19 | console.error("chrome.runtime.lastError in chrome.storage.session.get:", lastError); |
| 20 | // 无视storage API错误,继续执行 |
| 21 | } |
| 22 | resolve(value[key]); |
| 23 | }); |
| 24 | }); |
| 25 | } |
| 26 | |
| 27 | set<T>(key: string, value: T): Promise<void> { |
| 28 | return new Promise((resolve) => { |
| 29 | chrome.storage.session.set( |
| 30 | { |
| 31 | [key]: value, |
| 32 | }, |
| 33 | () => { |
| 34 | const lastError = chrome.runtime.lastError; |
| 35 | if (lastError) { |
| 36 | console.error("chrome.runtime.lastError in chrome.storage.session.set:", lastError); |
| 37 | // 无视storage API错误,继续执行 |
| 38 | } |
| 39 | resolve(); |
| 40 | } |
| 41 | ); |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | batchSet(data: { [key: string]: any }): Promise<void> { |
| 46 | return new Promise((resolve) => { |
| 47 | chrome.storage.session.set(data, () => { |
| 48 | const lastError = chrome.runtime.lastError; |
| 49 | if (lastError) { |
| 50 | console.error("chrome.runtime.lastError in chrome.storage.session.set:", lastError); |
| 51 | // 无视storage API错误,继续执行 |
| 52 | } |
| 53 | resolve(); |
| 54 | }); |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | has(key: string): Promise<boolean> { |
| 59 | return new Promise((resolve) => { |
| 60 | chrome.storage.session.get(key, (value) => { |
| 61 | const lastError = chrome.runtime.lastError; |
| 62 | if (lastError) { |
| 63 | console.error("chrome.runtime.lastError in chrome.storage.session.get:", lastError); |
| 64 | // 无视storage API错误,继续执行 |
| 65 | } |
| 66 | resolve(value[key] !== undefined); |
| 67 | }); |
| 68 | }); |
| 69 | } |
| 70 |
nothing calls this directly
no outgoing calls
no test coverage detected