fix: background-script fetch (CSP/mixed-content), prefer-Spotify links, toolbar icon (task/fix-extension-and-linkui)
The extension linked nothing and the resolver saw no requests: the content script fetched http://localhost:8787 directly from the HTTPS reddit page, which reddit's CSP / mixed-content blocks. Move the network call to a background script (extension origin, exempt) and add stage logging so failures are visible. - extension/background.js (new): does the resolver fetch on message; sets the toolbar badge. - extension/content.js: talks to background via runtime messaging (no page-context fetch); [rsl] console logs at boot/root/candidates/resolve/scan; single primary link. - extension/manifest.json: background.scripts + browser_action (icon.svg, title). - extension/{styles.css,icon.svg}: platform-coloured link (green=spotify, teal=bandcamp) + toolbar icon. - service/lib.js: primaryOf()/isSearchUrl() — link Spotify when the artist is on Spotify, else Bandcamp, else Spotify search; spotifyResult/mbResult attach `primary` (unit-tested). - README: link behaviour, toolbar, Troubleshooting. Verified: scripts/check.sh green (10 tests); resolver returns `primary` end-to-end. The in-browser fix is logic-verified only (no headless Firefox here) — reload the temp add-on and watch the page console `[rsl]` logs to confirm. Source: project human-feedback 2026-06-16 (notes 01KV8VC58QMYBDY6VVVJHR8YNY + 01KV91AMJCN2C4GFCKMKQRGNXE). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+22
-1
@@ -1,7 +1,7 @@
|
||||
// Unit tests for the resolver's pure logic (run with `node --test`). Zero-dep.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { norm, bandcampSearch, spotifySearch, pickArtist, spotifyResult, relUrls, mbResult } from "./lib.js";
|
||||
import { norm, bandcampSearch, spotifySearch, pickArtist, spotifyResult, relUrls, mbResult, primaryOf, isSearchUrl } from "./lib.js";
|
||||
|
||||
test("norm lowercases, trims, NFKC-normalizes", () => {
|
||||
assert.equal(norm(" Cerebral Bore "), "cerebral bore");
|
||||
@@ -35,8 +35,28 @@ test("spotifyResult prefers the direct url, falls back to search", () => {
|
||||
assert.equal(direct.spotify, "https://open.spotify.com/artist/abc");
|
||||
assert.match(direct.bandcamp, /^https:\/\/bandcamp\.com\/search\?q=Devourment/);
|
||||
|
||||
assert.deepEqual(direct.primary, { platform: "spotify", url: "https://open.spotify.com/artist/abc" });
|
||||
|
||||
const noUrl = spotifyResult({ name: "Devourment" });
|
||||
assert.equal(noUrl.spotify, "https://open.spotify.com/search/Devourment");
|
||||
assert.equal(noUrl.primary.platform, "spotify"); // search fallback still points at spotify
|
||||
});
|
||||
|
||||
test("primaryOf / isSearchUrl: prefer direct spotify, else direct bandcamp, else spotify search", () => {
|
||||
assert.equal(isSearchUrl("https://open.spotify.com/search/X"), true);
|
||||
assert.equal(isSearchUrl("https://open.spotify.com/artist/abc"), false);
|
||||
assert.deepEqual(
|
||||
primaryOf({ spotify: "https://open.spotify.com/artist/abc", bandcamp: "https://bandcamp.com/search?q=X&item_type=b" }),
|
||||
{ platform: "spotify", url: "https://open.spotify.com/artist/abc" },
|
||||
);
|
||||
assert.deepEqual(
|
||||
primaryOf({ spotify: "https://open.spotify.com/search/X", bandcamp: "https://x.bandcamp.com/" }),
|
||||
{ platform: "bandcamp", url: "https://x.bandcamp.com/" },
|
||||
);
|
||||
assert.deepEqual(
|
||||
primaryOf({ spotify: "https://open.spotify.com/search/X", bandcamp: "https://bandcamp.com/search?q=X&item_type=b" }),
|
||||
{ platform: "spotify", url: "https://open.spotify.com/search/X" },
|
||||
);
|
||||
});
|
||||
|
||||
test("relUrls picks direct bandcamp + spotify from MB relations, tolerates junk", () => {
|
||||
@@ -64,6 +84,7 @@ test("mbResult prefers direct links, falls back to search per-platform", () => {
|
||||
);
|
||||
assert.equal(direct.bandcamp, "https://cattledecapitation.bandcamp.com/");
|
||||
assert.equal(direct.spotify, "https://open.spotify.com/artist/x");
|
||||
assert.deepEqual(direct.primary, { platform: "spotify", url: "https://open.spotify.com/artist/x" });
|
||||
|
||||
const fallback = mbResult({ name: "Cerebral Bore" }, null);
|
||||
assert.equal(fallback.spotify, "https://open.spotify.com/search/Cerebral%20Bore");
|
||||
|
||||
Reference in New Issue
Block a user