xiMatrix

filter net requests according to source, destination and type  https://addons.mozilla.org/firefox/addon/ximatrix/
git clone https://git.ce9e.org/xiMatrix.git

commit
e43afc5a954ade5f8b2b7dbad63ce9ca675e6fe5
parent
d170cb7368cc6aca1490181a014020d4855e8f0d
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-10-04 16:14
rm option to disable recording

reverts 0d34234

It turns out that this is not realistic.

Diffstat

M README.md 1 -
M src/bg.js 46 ++++++++++++++++------------------------------
M src/popup.css 4 +---
M src/popup.html 4 ----
M src/popup.js 6 ------
M src/storage.js 2 --

6 files changed, 17 insertions, 46 deletions


diff --git a/README.md b/README.md

@@ -16,7 +16,6 @@ Available for Firefox here: https://addons.mozilla.org/firefox/addon/ximatrix/
   16    16 	-	keyboard navigation
   17    17 	-	simpler code
   18    18 	-	rules are encoded as JSON
   19    -1 	-	recording requests can be disabled to improve performance
   20    19 	-	it is possible to control inline scripts, styles, and images
   21    20 	-	there is a separate column for fonts
   22    21 -	disadvantages / simplifications

diff --git a/src/bg.js b/src/bg.js

@@ -65,22 +65,19 @@ var getRules = async function(context) {
   65    65 };
   66    66 
   67    67 var pushRequest = async function(tabId, hostname, type) {
   68    -1     var recording = await storage.get('recording');
   69    -1     if (recording) {
   70    -1         await storage.change('requests', requests => {
   71    -1             if (!requests[tabId]) {
   72    -1                 requests[tabId] = {};
   73    -1             }
   74    -1             if (!requests[tabId][hostname]) {
   75    -1                 requests[tabId][hostname] = {};
   76    -1             }
   77    -1             if (!requests[tabId][hostname][type]) {
   78    -1                 requests[tabId][hostname][type] = 0;
   79    -1             }
   80    -1             requests[tabId][hostname][type] += 1;
   81    -1             return requests;
   82    -1         });
   83    -1     }
   -1    68     await storage.change('requests', requests => {
   -1    69         if (!requests[tabId]) {
   -1    70             requests[tabId] = {};
   -1    71         }
   -1    72         if (!requests[tabId][hostname]) {
   -1    73             requests[tabId][hostname] = {};
   -1    74         }
   -1    75         if (!requests[tabId][hostname][type]) {
   -1    76             requests[tabId][hostname][type] = 0;
   -1    77         }
   -1    78         requests[tabId][hostname][type] += 1;
   -1    79         return requests;
   -1    80     });
   84    81 };
   85    82 
   86    83 var clearRequests = async function(tabId) {
@@ -107,16 +104,14 @@ browser.runtime.onMessage.addListener(async (msg, sender) => {
  107   104             getPatterns(),
  108   105         ]);
  109   106         const context = getHostname(tab.url, patterns);
  110    -1         const [rules, requests, recording] = await Promise.all([
   -1   107         const [rules, requests] = await Promise.all([
  111   108             getRules(context),
  112   109             storage.get('requests'),
  113    -1             storage.get('recording'),
  114   110         ]);
  115   111         return {
  116   112             context: context,
  117   113             rules: rules,
  118   114             requests: requests[tab.id] || {},
  119    -1             recording: recording,
  120   115         };
  121   116     } else if (msg.type === 'setRule') {
  122   117         await setRule(
@@ -148,8 +143,6 @@ browser.runtime.onMessage.addListener(async (msg, sender) => {
  148   143         });
  149   144     } else if (msg.type === 'securitypolicyviolation') {
  150   145         await pushRequest(sender.tab.id, 'inline', msg.data);
  151    -1     } else if (msg.type === 'toggleRecording') {
  152    -1         await storage.change('recording', recording => !recording);
  153   146     }
  154   147 });
  155   148 
@@ -207,18 +200,11 @@ browser.webRequest.onBeforeSendHeaders.addListener(async details => {
  207   200 browser.webRequest.onHeadersReceived.addListener(async details => {
  208   201     var patterns = await getPatterns();
  209   202     var context = getHostname(details.url, patterns);
  210    -1     var [rules, recording] = await Promise.all([
  211    -1         getRules(context),
  212    -1         storage.get('recording'),
  213    -1     ]);
   -1   203     var rules = await getRules(context);
  214   204     var csp = (type, value) => {
  215   205         var name = 'Content-Security-Policy';
  216   206         if (shared.shouldAllow(rules, context, 'inline', type)) {
  217    -1             if (recording) {
  218    -1                 name = 'Content-Security-Policy-Report-Only';
  219    -1             } else {
  220    -1                 return;
  221    -1             }
   -1   207             name = 'Content-Security-Policy-Report-Only';
  222   208         }
  223   209         details.responseHeaders.push({
  224   210             name: name,

diff --git a/src/popup.css b/src/popup.css

@@ -10,9 +10,7 @@
   10    10 .toolbar {
   11    11 	display: flex;
   12    12 	gap: 0.5em;
   13    -1 }
   14    -1 .toolbar label {
   15    -1 	flex-grow: 1;
   -1    13 	justify-content: end;
   16    14 }
   17    15 
   18    16 table {

diff --git a/src/popup.html b/src/popup.html

@@ -7,10 +7,6 @@
    7     7 <body>
    8     8 	<table></table>
    9     9 	<div class="toolbar">
   10    -1 		<label>
   11    -1 			<input type="checkbox" name="recording">
   12    -1 			recording
   13    -1 		</label>
   14    10 		<button type="button" name="commit" disabled>Commit</button>
   15    11 		<button type="button" name="reset" disabled>Reset</button>
   16    12 		<button type="button" name="settings">Edit rules</button>

diff --git a/src/popup.js b/src/popup.js

@@ -7,7 +7,6 @@ var requests;
    7     7 var rules;
    8     8 
    9     9 var table = document.querySelector('table');
   10    -1 var recording = document.querySelector('[name="recording"]');
   11    10 var commitButton = document.querySelector('[name="commit"]');
   12    11 var resetButton = document.querySelector('[name="reset"]');
   13    12 
@@ -139,7 +138,6 @@ var loadContext = async function() {
  139   138     context = data.context;
  140   139     requests = data.requests;
  141   140     rules = data.rules;
  142    -1     recording.checked = data.recording;
  143   141     commitButton.disabled = !rules.dirty;
  144   142     resetButton.disabled = !rules.dirty;
  145   143 
@@ -165,10 +163,6 @@ document.addEventListener('DOMContentLoaded', async () => {
  165   163     await loadContext();
  166   164 });
  167   165 
  168    -1 recording.addEventListener('change', async () => {
  169    -1     await sendMessage('toggleRecording');
  170    -1 });
  171    -1 
  172   166 commitButton.addEventListener('click', async () => {
  173   167     await sendMessage('commit', context);
  174   168     commitButton.disabled = true;

diff --git a/src/storage.js b/src/storage.js

@@ -4,13 +4,11 @@ var STORAGE_DEFAULTS = {
    4     4     'rules': {},
    5     5     'savedRules': {},
    6     6     'requests': {},
    7    -1     'recording': true,
    8     7 };
    9     8 var STORAGE_AREAS = {
   10     9     'rules': browser.storage.local,
   11    10     'savedRules': browser.storage.local,
   12    11     'requests': browser.storage.session,
   13    -1     'recording': browser.storage.local,
   14    12 };
   15    13 
   16    14 var lock = Promise.resolve();