Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ghostery/ghostery-extension
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f489c7f66986032522bf90d5103863d49cb3c015
Choose a base ref
...
head repository: ghostery/ghostery-extension
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 75f4cf569834d714dcb722c04c76a970103cb4ce
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Sep 6, 2024

  1. fix: fallback to storage.local when IndexedDB is corrupted

    smalluban committed Sep 6, 2024
    Copy the full SHA
    75f4cf5 View commit details
Showing with 40 additions and 24 deletions.
  1. +1 −0 extension-manifest-v3/src/manifest.firefox.json
  2. +39 −24 extension-manifest-v3/src/utils/engines.js
1 change: 1 addition & 0 deletions extension-manifest-v3/src/manifest.firefox.json
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
"webNavigation",
"webRequest",
"webRequestBlocking",
"unlimitedStorage",
"http://*/*",
"https://*/*",
"ws://*/*",
63 changes: 39 additions & 24 deletions extension-manifest-v3/src/utils/engines.js
Original file line number Diff line number Diff line change
@@ -90,12 +90,25 @@ async function getDB() {

async function loadFromStorage(name) {
try {
const db = await getDB();

const tx = db.transaction('engines');
const table = tx.objectStore('engines');

const engineBytes = await table.get(name);
const engineBytes = await getDB()
.then((db) => {
const tx = db.transaction('engines');
const table = tx.objectStore('engines');
return table.get(name);
})
.catch((e) => {
// Suppress the private browsing mode in Firefox
if (!e.message?.includes('database that did not allow mutations')) {
captureException(e);
}

if (__PLATFORM__ === 'firefox') {
const key = `engines:${name}`;
return chrome.storage.local.get([key]).then((data) => data[key]);
} else {
throw e;
}
});

if (engineBytes) {
const engine = deserializeEngine(engineBytes);
@@ -104,17 +117,6 @@ async function loadFromStorage(name) {
return engine;
}
} catch (e) {
const msg = e.message || '';

if (
// Adblocker core updates the engine version
!msg.includes('serialized engine version mismatch') &&
// Private Browsing mode in Firefox
!msg.includes('database that did not allow mutations')
) {
captureException(e);
}

console.error(`[engines] Failed to load engine "${name}" from storage`, e);
}

@@ -123,15 +125,28 @@ async function loadFromStorage(name) {

async function saveToStorage(name) {
const engine = loadFromMemory(name);
const db = await getDB();
const serialized = engine?.serialize();

const tx = db.transaction('engines', 'readwrite');
const table = tx.objectStore('engines');
try {
const db = await getDB();

if (engine) {
await table.put(engine.serialize(), name);
} else {
await table.delete(name);
const tx = db.transaction('engines', 'readwrite');
const table = tx.objectStore('engines');

if (engine) {
await table.put(serialized, name);
} else {
await table.delete(name);
}
} catch (e) {
if (__PLATFORM__ === 'firefox') {
const key = `engines:${name}`;
const data = engine ? { [key]: serialized } : { [key]: null };

return chrome.storage.local.set(data);
}

throw e;
}
}