Skip to content

Commit

Permalink
fix: update autoconsent library to 12.x
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Dec 10, 2024
1 parent 7d73711 commit 7f979b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 47 deletions.
12 changes: 7 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"webextension-polyfill": "^0.12.0"
},
"dependencies": {
"@duckduckgo/autoconsent": "^10.17.0",
"@duckduckgo/autoconsent": "^12.2.0",
"@ghostery/adblocker": "^2.1.1",
"@ghostery/adblocker-webextension": "^2.1.1",
"@github/relative-time-element": "^4.4.4",
Expand Down
46 changes: 5 additions & 41 deletions src/background/autoconsent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import rules from '@duckduckgo/autoconsent/rules/rules.json';
import { snippets } from '@duckduckgo/autoconsent/lib/eval-snippets';

import { parse } from 'tldts-experimental';
import { store } from 'hybrids';

Expand All @@ -35,9 +35,7 @@ async function initialize(msg, tab, frameId) {
enableCosmeticRules: false,
},
},
{
frameId,
},
{ frameId },
);
} catch {
// The error is thrown when the tab is not ready to receive messages,
Expand All @@ -46,44 +44,10 @@ async function initialize(msg, tab, frameId) {
}
}

async function evalCode(snippetId, id, tabId, frameId) {
const [result] = await chrome.scripting.executeScript({
target: {
tabId,
frameIds: [frameId],
},
world:
chrome.scripting.ExecutionWorld?.MAIN ??
(__PLATFORM__ === 'firefox' ? undefined : 'MAIN'),
func: snippets[snippetId],
});

await chrome.tabs.sendMessage(
tabId,
{
action: 'autoconsent',
id,
type: 'evalResp',
result: result.result,
},
{
frameId,
},
);
}

chrome.runtime.onMessage.addListener((msg, sender) => {
if (msg.action !== 'autoconsent') return;
if (!sender.tab) return;

const frameId = sender.frameId;
if (msg.action !== 'autoconsent' || !sender.tab) return;

switch (msg.type) {
case 'init':
return initialize(msg, sender.tab, frameId);
case 'eval':
return evalCode(msg.snippetId, msg.id, sender.tab.id, frameId);
default:
break;
if (msg.type === 'init') {
initialize(msg, sender.tab, sender.frameId);
}
});

0 comments on commit 7f979b4

Please sign in to comment.