A bundled add-on that answers cookie consent dialogs, rejecting all but the essentials by default (or accepting, if the user prefers the banner simply gone), so pages open without one. Built on DuckDuckGo's autoconsent (MPL-2.0): its rule bundle covers hundreds of consent managers, and a reject-button heuristic handles unknown banners in reject mode. The library runs through the page-inject slot in every http(s) frame's isolated world; the add-on hands each frame the user's settings and the rules, and counts what was handled per site for the panel, which also excludes a site with one click. build-inject.js assembles inject.js from the library in node_modules plus the glue, and copies the compact rules and licence into the add-on so a rule update can ship through the add-on channel. Host side: page-inject scripts get theseus.evalInPage for the few rules that need the page's own JavaScript (they already reach the page via contextBridge, so no new trust tier), and api.tabs is open to page-inject add-ons as well as request-filter ones.
38 lines
2 KiB
JavaScript
38 lines
2 KiB
JavaScript
#!/usr/bin/env node
|
|
// Builds inject.js — the page-inject script — from DuckDuckGo's autoconsent
|
|
// library (node_modules, MPL-2.0) plus the glue that connects it to this
|
|
// add-on over theseus.invoke / theseus.evalInPage. Also copies the compact
|
|
// rule bundle and the licence next to it, so the add-on tarball is self-
|
|
// contained and a rule update ships through the add-on channel.
|
|
//
|
|
// node bundled-addons/consent/build-inject.js
|
|
//
|
|
// Page-inject scripts run through `new Function("theseus", "require", src)`
|
|
// in the isolated world, with require() limited to "electron", so the
|
|
// library is inlined as a CommonJS module rather than required.
|
|
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
|
|
const here = __dirname;
|
|
const pkgDir = path.join(here, "..", "..", "node_modules", "@duckduckgo", "autoconsent");
|
|
const lib = fs.readFileSync(path.join(pkgDir, "dist", "autoconsent.cjs.js"), "utf8");
|
|
const version = JSON.parse(fs.readFileSync(path.join(pkgDir, "package.json"), "utf8")).version;
|
|
const glue = fs.readFileSync(path.join(here, "inject-glue.js"), "utf8");
|
|
|
|
const out = [
|
|
`// GENERATED by build-inject.js — do not edit. autoconsent ${version} (DuckDuckGo, MPL-2.0) + Theseus glue.`,
|
|
`(function () {`,
|
|
` const module = { exports: {} }; const exports = module.exports;`,
|
|
` ${lib.replace(/\n/g, "\n ")}`,
|
|
` const AutoConsentCtor = module.exports.default || module.exports.AutoConsent || module.exports;`,
|
|
` const AUTOCONSENT_VERSION = ${JSON.stringify(version)};`,
|
|
` ${glue.replace(/\n/g, "\n ")}`,
|
|
`})();`,
|
|
``,
|
|
].join("\n");
|
|
fs.writeFileSync(path.join(here, "inject.js"), out);
|
|
fs.mkdirSync(path.join(here, "rules"), { recursive: true });
|
|
fs.copyFileSync(path.join(pkgDir, "rules", "compact-rules.json"), path.join(here, "rules", "compact-rules.json"));
|
|
fs.copyFileSync(path.join(pkgDir, "LICENSE"), path.join(here, "LICENSE-autoconsent"));
|
|
fs.writeFileSync(path.join(here, "rules", "VERSION"), version + "\n");
|
|
console.log(`inject.js: ${out.length} bytes, autoconsent ${version}, rules copied`);
|