# HG changeset patch # User Denis Lisov # Date 1549672685 -10800 # Node ID 89239e60d9e1a2a11c0b6813aa7f98d083eecc45 # Parent 0e8c61f3373d863ef077c2cb840ced710a9a8002 Enable on privileged pages There are contexts in Firefox (for example, the default new tab page) that contain links to http(s) resources but are considered privileged. In these contexts `menus.onShown` does not provide the link URL to the extension and Open Incognito disables the context menu entry. However, if the entry is not disabled, the `onClicked` listener will actually know the link URL because a user's click on the extension's menu item is considered to be an explicit permission, so Open Incognito could work. Keep the menu item enabled if the URL is not available. There is a drawback that the item will be enabled but do nothing if the actual link has an unknown/unsupported protocol, but this is probably a more rare situation. diff -r 0e8c61f3373d -r 89239e60d9e1 background.js --- a/background.js Fri Dec 14 22:18:02 2018 +0100 +++ b/background.js Sat Feb 09 03:38:05 2019 +0300 @@ -8,17 +8,23 @@ 'use strict'; +function hasKnownProtocol(link) { + return (link.startsWith('http:') || + link.startsWith('https:') || + link.startsWith('ftp:')); +} + function onMenuShown(info, tab) { let enabled = !tab.incognito && - typeof info.linkUrl !== 'undefined' && - (info.linkUrl.startsWith('http:') || - info.linkUrl.startsWith('https:') || - info.linkUrl.startsWith('ftp:')); + (typeof info.linkUrl === 'undefined' || hasKnownProtocol(info.linkUrl)); browser.menus.update('open-link-in-private-mode', {enabled}); browser.menus.refresh(); } async function onClicked(info, tab) { + if(!hasKnownProtocol(info.linkUrl)) { + return; + } let activeTabs = await browser.tabs.query({ active: true, currentWindow: false,