fix: allow rendered about fallback frames

This commit is contained in:
Darío Sevilla committed 2026-10-15 08:27:15 +00:00
1 parent 276c0fc8b1
commit 8a5fecc731
8 files changed
+351 -7

No files matched your search

+2 -1
View File
@@ -5,7 +5,7 @@ X GeoBlock is a Manifest V3 browser extension for Chromium and Firefox. While yo
## Features ## Features
- Processes posts already on the page and posts loaded by infinite scrolling. - Processes posts already on the page and posts loaded by infinite scrolling.
- Performs authenticated About-page requests in the background. If X returns only its empty application shell, an invisible same-origin frame inside the current X page renders the account data without opening tabs or windows. - Performs authenticated About-page requests in the background. If X returns only its empty application shell, an invisible same-origin frame inside the current X page renders the account data without opening tabs or windows. A narrowly scoped network rule allows only these `/about` subframes to render despite X's anti-framing headers.
- Caches account results locally for 30 days, with manual clearing available. - Caches account results locally for 30 days, with manual clearing available.
- Coalesces duplicate lookups and spaces network requests to reduce load on X. - Coalesces duplicate lookups and spaces network requests to reduce load on X.
- Skips followed accounts. - Skips followed accounts.
@@ -55,6 +55,7 @@ The location picker contains the ISO 3166-1 countries, plus Kosovo, using Englis
- `storage`: saves settings and the local user cache. - `storage`: saves settings and the local user cache.
- `offscreen`: parses returned HTML without opening visible tabs. - `offscreen`: parses returned HTML without opening visible tabs.
- `declarativeNetRequestWithHostAccess`: removes anti-framing response headers only from `x.com/*/about` subframe requests so the fallback can render.
- `https://x.com/*`: reads About pages and runs the feed filter on X. - `https://x.com/*`: reads About pages and runs the feed filter on X.
## License ## License
+2 -2
View File
@@ -5,7 +5,7 @@
1. The content script observes X's timeline and extracts an author from each canonical `/user/status/id` link. 1. The content script observes X's timeline and extracts an author from each canonical `/user/status/id` link.
2. The service worker checks the local cache and coalesces concurrent lookups for the same username. 2. The service worker checks the local cache and coalesces concurrent lookups for the same username.
3. On a cache miss, the background process requests `https://x.com/<user>/about` with the browser's existing X session. 3. On a cache miss, the background process requests `https://x.com/<user>/about` with the browser's existing X session.
4. Chromium passes fetched HTML to an offscreen document; Firefox can parse it in its background page. When X returns only its SPA shell, an invisible same-origin frame inside the current X page renders the URL. The content script reads the location row and immediately destroys the frame. This does not create a browser tab or window. 4. Chromium passes fetched HTML to an offscreen document; Firefox can parse it in its background page. When X returns only its SPA shell, an invisible same-origin frame inside the current X page renders the URL. A static network rule removes CSP and `X-Frame-Options` only from matching `/about` subframe responses. The content script reads the location row and immediately destroys the frame. This does not create a browser tab or window.
5. The worker caches the result and compares the country with the configured blacklist. 5. The worker caches the result and compares the country with the configured blacklist.
6. The content script hides the post only when the country matches and the account is not followed. 6. The content script hides the post only when the country matches and the account is not followed.
@@ -22,4 +22,4 @@ Failed or ambiguous lookups fail open: the post remains visible. Empty results a
## Compatibility ## Compatibility
The Chromium package requires Chrome 109 or newer. Firefox 109 or newer uses a browser-specific background-page manifest and does not require the Chromium offscreen-document API. The Chromium package requires Chrome 109 or newer. Firefox 113 or newer uses a browser-specific background-page manifest and does not require the Chromium offscreen-document API.
+11 -1
View File
@@ -11,7 +11,8 @@
}, },
"permissions": [ "permissions": [
"storage", "storage",
"offscreen" "offscreen",
"declarativeNetRequestWithHostAccess"
], ],
"host_permissions": [ "host_permissions": [
"https://x.com/*" "https://x.com/*"
@@ -22,6 +23,15 @@
"background": { "background": {
"service_worker": "background.js" "service_worker": "background.js"
}, },
"declarative_net_request": {
"rule_resources": [
{
"id": "about_page_frame",
"enabled": true,
"path": "rules/about-frame.json"
}
]
},
"content_scripts": [ "content_scripts": [
{ {
"matches": [ "matches": [
+220
View File
@@ -0,0 +1,220 @@
{
"name": "x-geoblock",
"version": "1.0.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "x-geoblock",
"version": "1.0.1",
"license": "MIT",
"devDependencies": {
"linkedom": "^0.18.12"
},
"engines": {
"node": ">=18"
}
},
"node_modules/boolbase": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz",
"integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==",
"dev": true,
"license": "ISC"
},
"node_modules/css-select": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/css-select/-/css-select-5.2.2.tgz",
"integrity": "sha512-TizTzUddG/xYLA3NXodFM0fSbNizXjOKhqiQQwvhlspadZokn1KDy0NZFS0wuEubIYAV5/c1/lAr0TaaFXEXzw==",
"dev": true,
"license": "BSD-2-Clause",
"dependencies": {
"boolbase": "^1.0.0",
"css-what": "^6.1.0",
"domhandler": "^5.0.2",
"domutils": "^3.0.1",
"nth-check": "^2.0.1"
},
"funding": {
"url": "https://github.com/sponsors/fb55"
}
},
"node_modules/css-what": {
"version": "6.2.2",
"resolved": "https://registry.npmjs.org/css-what/-/css-what-6.2.2.tgz",
"integrity": "sha512-u/O3vwbptzhMs3L1fQE82ZSLHQQfto5gyZzwteVIEyeaY5Fc7R4dapF/BvRoSYFeqfBk4m0V1Vafq5Pjv25wvA==",
"dev": true,
"license": "BSD-2-Clause",
"engines": {
"node": ">= 6"
},
"funding": {
"url": "https://github.com/sponsors/fb55"
}
},
"node_modules/cssom": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/cssom/-/cssom-0.5.0.tgz",
"integrity": "sha512-iKuQcq+NdHqlAcwUY0o/HL69XQrUaQdMjmStJ8JFmUaiiQErlhrmuigkg/CU4E2J0IyUKUrMAgl36TvN67MqTw==",
"dev": true,
"license": "MIT"
},
"node_modules/dom-serializer": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz",
"integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==",
"dev": true,
"license": "MIT",
"dependencies": {
"domelementtype": "^2.3.0",
"domhandler": "^5.0.2",
"entities": "^4.2.0"
},
"funding": {
"url": "https://github.com/cheeriojs/dom-serializer?sponsor=1"
}
},
"node_modules/domelementtype": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz",
"integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==",
"dev": true,
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/fb55"
}
],
"license": "BSD-2-Clause"
},
"node_modules/domhandler": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz",
"integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==",
"dev": true,
"license": "BSD-2-Clause",
"dependencies": {
"domelementtype": "^2.3.0"
},
"engines": {
"node": ">= 4"
},
"funding": {
"url": "https://github.com/fb55/domhandler?sponsor=1"
}
},
"node_modules/domutils": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/domutils/-/domutils-3.2.2.tgz",
"integrity": "sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==",
"dev": true,
"license": "BSD-2-Clause",
"dependencies": {
"dom-serializer": "^2.0.0",
"domelementtype": "^2.3.0",
"domhandler": "^5.0.3"
},
"funding": {
"url": "https://github.com/fb55/domutils?sponsor=1"
}
},
"node_modules/entities": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
"integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==",
"dev": true,
"license": "BSD-2-Clause",
"engines": {
"node": ">=0.12"
},
"funding": {
"url": "https://github.com/fb55/entities?sponsor=1"
}
},
"node_modules/html-escaper": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz",
"integrity": "sha512-RuMffC89BOWQoY0WKGpIhn5gX3iI54O6nRA0yC124NYVtzjmFWBIiFd8M0x+ZdX0P9R4lADg1mgP8C7PxGOWuQ==",
"dev": true,
"license": "MIT"
},
"node_modules/htmlparser2": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-10.1.0.tgz",
"integrity": "sha512-VTZkM9GWRAtEpveh7MSF6SjjrpNVNNVJfFup7xTY3UpFtm67foy9HDVXneLtFVt4pMz5kZtgNcvCniNFb1hlEQ==",
"dev": true,
"funding": [
"https://github.com/fb55/htmlparser2?sponsor=1",
{
"type": "github",
"url": "https://github.com/sponsors/fb55"
}
],
"license": "MIT",
"dependencies": {
"domelementtype": "^2.3.0",
"domhandler": "^5.0.3",
"domutils": "^3.2.2",
"entities": "^7.0.1"
}
},
"node_modules/htmlparser2/node_modules/entities": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz",
"integrity": "sha512-TWrgLOFUQTH994YUyl1yT4uyavY5nNB5muff+RtWaqNVCAK408b5ZnnbNAUEWLTCpum9w6arT70i1XdQ4UeOPA==",
"dev": true,
"license": "BSD-2-Clause",
"engines": {
"node": ">=0.12"
},
"funding": {
"url": "https://github.com/fb55/entities?sponsor=1"
}
},
"node_modules/linkedom": {
"version": "0.18.12",
"resolved": "https://registry.npmjs.org/linkedom/-/linkedom-0.18.12.tgz",
"integrity": "sha512-jalJsOwIKuQJSeTvsgzPe9iJzyfVaEJiEXl+25EkKevsULHvMJzpNqwvj1jOESWdmgKDiXObyjOYwlUqG7wo1Q==",
"dev": true,
"license": "ISC",
"dependencies": {
"css-select": "^5.1.0",
"cssom": "^0.5.0",
"html-escaper": "^3.0.3",
"htmlparser2": "^10.0.0",
"uhyphen": "^0.2.0"
},
"engines": {
"node": ">=16"
},
"peerDependencies": {
"canvas": ">= 2"
},
"peerDependenciesMeta": {
"canvas": {
"optional": true
}
}
},
"node_modules/nth-check": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz",
"integrity": "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==",
"dev": true,
"license": "BSD-2-Clause",
"dependencies": {
"boolbase": "^1.0.0"
},
"funding": {
"url": "https://github.com/fb55/nth-check?sponsor=1"
}
},
"node_modules/uhyphen": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/uhyphen/-/uhyphen-0.2.0.tgz",
"integrity": "sha512-qz3o9CHXmJJPGBdqzab7qAYuW8kQGKNEuoHFYrBwV6hWIMcpAmxDLXojcHfFr9US1Pe6zUswEIJIbLI610fuqA==",
"dev": true,
"license": "ISC"
}
}
}
+4 -1
View File
@@ -14,5 +14,8 @@
"engines": { "engines": {
"node": ">=18" "node": ">=18"
}, },
"license": "MIT" "license": "MIT",
"devDependencies": {
"linkedom": "^0.18.12"
}
} }
+18
View File
@@ -0,0 +1,18 @@
[
{
"id": 1,
"priority": 1,
"action": {
"type": "modifyHeaders",
"responseHeaders": [
{ "header": "content-security-policy", "operation": "remove" },
{ "header": "x-frame-options", "operation": "remove" }
]
},
"condition": {
"urlFilter": "||x.com/*/about",
"initiatorDomains": ["x.com"],
"resourceTypes": ["sub_frame"]
}
}
]
+2 -2
View File
@@ -8,7 +8,7 @@ const dist = join(root, "dist");
const baseManifest = JSON.parse(readFileSync(join(root, "manifest.json"), "utf8")); const baseManifest = JSON.parse(readFileSync(join(root, "manifest.json"), "utf8"));
const version = baseManifest.version; const version = baseManifest.version;
const sharedFiles = [ const sharedFiles = [
"background.js", "content.js", "content.css", "page-bridge.js", "icons", "lib", "options", "popup" "background.js", "content.js", "content.css", "page-bridge.js", "icons", "lib", "options", "popup", "rules"
]; ];
rmSync(dist, { recursive: true, force: true }); rmSync(dist, { recursive: true, force: true });
@@ -35,7 +35,7 @@ firefoxManifest.background = {
firefoxManifest.browser_specific_settings = { firefoxManifest.browser_specific_settings = {
gecko: { gecko: {
id: "x-geoblock@dasemu.github.io", id: "x-geoblock@dasemu.github.io",
strict_min_version: "109.0" strict_min_version: "113.0"
} }
}; };
const firefoxDirectory = prepare("firefox", firefoxManifest); const firefoxDirectory = prepare("firefox", firefoxManifest);
+92
View File
@@ -0,0 +1,92 @@
const test = require("node:test");
const assert = require("node:assert/strict");
const fs = require("node:fs");
const vm = require("node:vm");
const { parseHTML } = require("linkedom");
const parser = require("../lib/parser.js");
const contentSource = fs.readFileSync(require.resolve("../content.js"), "utf8");
function createContext(html, pathname, sendMessage) {
const { window, document } = parseHTML(html);
const runtimeListeners = [];
const context = {
document,
location: { pathname, href: `https://x.com${pathname}`, origin: "https://x.com" },
chrome: {
storage: {
sync: { get: async (defaults) => ({ ...defaults, enabled: true, blacklist: ["United States"] }) },
onChanged: { addListener() {} }
},
runtime: {
sendMessage,
onMessage: { addListener(listener) { runtimeListeners.push(listener); } }
}
},
XGeoParser: parser,
MutationObserver: window.MutationObserver,
Event: window.Event,
Element: window.Element,
Node: window.Node,
URL,
CSS: { escape: (value) => value },
console,
setTimeout,
clearTimeout,
setInterval,
clearInterval,
requestAnimationFrame: (callback) => setTimeout(callback, 0)
};
context.window = context;
context.window.top = context.window;
context.globalThis = context;
vm.runInNewContext(contentSource, context, { filename: "content.js" });
return { document, runtimeListeners };
}
test("manifest injects the About-page reporter into child frames", () => {
const manifest = require("../manifest.json");
const isolatedScript = manifest.content_scripts.find((entry) => entry.js.includes("content.js"));
assert.equal(isolatedScript.all_frames, true);
assert.equal(manifest.permissions.includes("declarativeNetRequestWithHostAccess"), true);
const rules = require("../rules/about-frame.json");
assert.deepEqual(rules[0].condition.resourceTypes, ["sub_frame"]);
assert.equal(rules[0].condition.urlFilter, "||x.com/*/about");
});
test("rendered About page reports the account country", async () => {
const messages = [];
createContext(`
<div role="tab" data-testid="pivot">
<svg><path d="M12 7c-1.93 0-3.5 1.57-3.5 3.5S10.07 14 12 14"></path></svg>
<span>Account based in</span><span>United States</span>
</div>`, "/ShitskinBlud/about", async (message) => messages.push(message));
await new Promise((resolve) => setTimeout(resolve, 0));
assert.deepEqual(JSON.parse(JSON.stringify(messages[0])), {
type: "about-page-result",
username: "ShitskinBlud",
country: "United States",
following: null,
profileLocation: null
});
});
test("blacklisted profile owner post is hidden", async () => {
const { document } = createContext(`
<main data-testid="primaryColumn">
<button data-testid="ShitskinBlud-follow">Follow</button>
<div data-testid="cellInnerDiv"><article>
<a href="/ShitskinBlud/status/2110603064012918829">post</a>
</article></div>
</main>`, "/ShitskinBlud/with_replies", async (message) => {
assert.equal(message.type, "lookup-user");
assert.equal(message.username, "ShitskinBlud");
assert.equal(message.followingHint, false);
return { ok: true, country: "United States", following: false, blocked: true };
});
await new Promise((resolve) => setTimeout(resolve, 20));
const article = document.querySelector("article");
assert.equal(article.dataset.xGeoBlockState, "blocked");
assert.equal(article.dataset.xGeoBlockCountry, "United States");
assert.equal(article.closest('[data-testid="cellInnerDiv"]').classList.contains("x-geoblock-hidden"), true);
});