Extension Context Menu Saves Active Webpage Instead of Clicked Link/Media
Author: codeCraft-RitikCreated Sep 28, 2026Updated Sep 28, 2026
Labelsbug
Overview
In the Linkwarden Web Extension (apps/extension), the service worker creates context menu items for multiple targets (["page", "selection", "link", "editable", "image", "video", "audio"]). When the user right-clicks a hyperlink or media element and selects "Add link to Linkwarden", the click handler completely ignores info.linkUrl, info.srcUrl, and info.selectionText. Instead, it unconditionally saves tab.url and tab.title.
Impact
- Broken Context Menu Functionality: When users right-click any link on Wikipedia, Reddit, GitHub, or a news site to bookmark it, Linkwarden bookmarks the page they are currently reading rather than the clicked hyperlink.
- Default Collection Ignored: Unlike the "Save all tabs" action (which respects
config.defaultCollection), the context menu hardcodes the collection name to"Unorganized".
Affected Files & Locations
- File:
apps/extension/src/pages/Background/index.ts - Lines: 204–281
// apps/extension/src/pages/Background/index.ts
204: async function genericOnClick(
205: info: OnClickData,
206: tab: chrome.tabs.Tab | undefined
207: ) {
208: const { syncBookmarks, baseUrl } = await getConfig();
209: const configured = await isConfigured();
210: if (!tab?.url || !tab?.title || !configured) {
211: return;
212: }
...
247: default:
248: if (syncBookmarks && hasAPI("bookmarks.create")) {
249: browser.bookmarks.create({
250: parentId: "1",
251: title: tab.title, // ❌ Always uses tab.title
252: url: tab.url, // ❌ Always uses tab.url
253: });
254: } else {
255: const config = await getConfig();
256: const newLink = await postLinkFetch(
257: baseUrl,
258: {
259: url: tab.url, // ❌ Ignores info.linkUrl and info.srcUrl!
260: collection: {
261: name: "Unorganized", // ❌ Ignores config.defaultCollection
262: },
263: tags: [],
264: name: tab.title,
265: description: tab.title,
266: },
267: config.apiKey
268: );Steps to Reproduce
- Install and configure the Linkwarden browser extension.
- Navigate to
https://news.ycombinator.com. - Right-click on any article link (e.g.,
https://example.com/great-article). - Click "Add link to Linkwarden" from the context menu.
- Open your Linkwarden dashboard.
- Result: A new link was created for
https://news.ycombinator.com(the parent tab) instead ofhttps://example.com/great-article(the target link).
Proposed Fix
Inspect info.linkUrl, info.srcUrl, and info.selectionText to determine the target link, and respect config.defaultCollection:
--- a/apps/extension/src/pages/Background/index.ts
+++ b/apps/extension/src/pages/Background/index.ts
@@ -207,9 +207,17 @@ async function genericOnClick(
) {
const { syncBookmarks, baseUrl } = await getConfig();
const configured = await isConfigured();
- if (!tab?.url || !tab?.title || !configured) {
+ if (!configured) return;
+
+ const targetUrl = info.linkUrl || info.srcUrl || tab?.url;
+ if (!targetUrl) return;
+
+ const targetTitle =
+ info.selectionText ||
+ (info.linkUrl ? info.linkUrl : tab?.title) ||
+ targetUrl;
+
switch (info.menuItemId) {
case "save-all-tabs": {
@@ -248,8 +256,8 @@ async function genericOnClick(
if (syncBookmarks && hasAPI("bookmarks.create")) {
browser.bookmarks.create({
parentId: "1",
- title: tab.title,
- url: tab.url,
+ title: targetTitle,
+ url: targetUrl,
});
} else {
const config = await getConfig();
@@ -258,13 +266,13 @@ async function genericOnClick(
const newLink = await postLinkFetch(
baseUrl,
{
- url: tab.url,
+ url: targetUrl,
collection: {
- name: "Unorganized",
+ name: config.defaultCollection || "Unorganized",
},
tags: [],
- name: tab.title,
- description: tab.title,
+ name: targetTitle,
+ description: targetTitle,
},
config.apiKey
);Source: linkwarden/linkwarden