Why this NS surrogate hose WebExtension context menu?

General discussion about web technology.

Why this NS surrogate hose WebExtension context menu?

Postby barbaz » Wed Aug 01, 2018 12:55 am

I use a NoScript surrogate to disable context menu hijacking by default while allowing it on specific sites -

replacement:
Code: Select all
window.addEventListener('contextmenu',function(ev){ev.stopPropagation();ev.stopImmediatePropagation();},true);

sources:
Code: Select all
@*


Unfortunately I just discovered this surrogate causes WebExtensions' context menu items registered by chrome.contextMenus API to do nothing. WebExtensions that rely on context menu, such as https://addons.mozilla.org/firefox/addon/copy-text-link/, end up completely hosed.

I thought WebExtensions were supposed to be more privileged than web content. And NoScript surrogates don't apply to privileged content.

So why would this surrogate even interfere with WebExtensions APIs?
Is there another way to write the surrogate that still works just as effectively but doesn't kill WebExtensions?

(Browser is Waterfox 56.2.2, NoScript version is 5.1.8.7rc3.)
*Always* check the changelogs BEFORE updating that important software!
Board search is currently partially broken: viewtopic.php?f=14&t=21752
Workaround: use your favorite search engine, add site:forums.informaction.com to your query
-
barbaz
Senior Member
 
Posts: 8524
Joined: Sat Aug 03, 2013 5:45 pm

Re: Why this NS surrogate hose WebExtension context menu?

Postby barbaz » Tue Aug 07, 2018 4:07 pm

Ok it's not a general WebExtension issue, but a weird side-effect of how the specific WebExtensions I'm using are implemented (Copy Text Link and Remove Anything). They use
Code: Select all
document.addEventListener("contextmenu", ...)

and it is this code the surrogate hoses.

This is not a NoScript issue either. A webpage including the same JS as the surrogate breaks these WebExtensions the same way.

So the issue here looks like some sort of lack of proper isolation between webpage-added event listeners and contentscript-added event listeners.

Interestingly, about:config > dom.event.contextmenu.enabled;false does *not* break these WebExtensions. But that's not a solution for me because I need context menu events enabled for a few sites. And it doesn't block a webpage that includes the surrogate's JS from hosing these WebExtensions.

Firefox 61.0.1 is likewise affected.

Not sure what to do at this point Image
*Always* check the changelogs BEFORE updating that important software!
Board search is currently partially broken: viewtopic.php?f=14&t=21752
Workaround: use your favorite search engine, add site:forums.informaction.com to your query
-
barbaz
Senior Member
 
Posts: 8524
Joined: Sat Aug 03, 2013 5:45 pm

Re: Why this NS surrogate hose WebExtension context menu?

Postby barbaz » Tue Aug 07, 2018 6:41 pm

Looks like dom.event.contextmenu.enabled doesn't enable/disable the entire contextmenu event. It only controls whether preventDefault can be used on contextmenu events. The NoScript surrogate I came up with maybe unnecessarily sledgehammer.

How to make a surrogate that emulates dom.event.contextmenu.enabled?
*Always* check the changelogs BEFORE updating that important software!
Board search is currently partially broken: viewtopic.php?f=14&t=21752
Workaround: use your favorite search engine, add site:forums.informaction.com to your query
-
barbaz
Senior Member
 
Posts: 8524
Joined: Sat Aug 03, 2013 5:45 pm


Return to Web Tech

Who is online

Users browsing this forum: No registered users and 1 guest