NoScript + Userscript Context Menu

Ask for help about NoScript, no registration needed to post
Greg01010100

NoScript + Userscript Context Menu

Post by Greg01010100 »

Hi guys. First of all thanks for this extension making Internet much safer. :) I have little userscript (Greasemonkey) that adds context menu item. Problem is it works only when i allow site. Is there any way to make it work without allowing site, cause this makes noscript pointless?

Code:

Code: Select all

// ==UserScript==
// @name            Instapaper context menu
// @grant           GM_openInTab
// ==/UserScript==
var menu = document.body.appendChild(document.createElement('menu'));
menu.id = 'instapaper-context-menu';
menu.type = 'context';
menu.innerHTML = '<menuitem label="Read on Instapaper" icon="https://staticinstapaper.s3.amazonaws.com/images/favicon.png"></menuitem>';
menu.firstElementChild.addEventListener('click', function() {
    GM_openInTab('http://www.instapaper.com/text?u=' + encodeURIComponent(location.href));
});
document.body.setAttribute('contextmenu', menu.id);
Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0
barbaz
Senior Member
Posts: 11143
Joined: Sat Aug 03, 2013 5:45 pm

Re: NoScript + Userscript Context Menu

Post by barbaz »

https://noscript.net/faq#qa1_2

When it fails, do you see anything related in the Browser Console? (Ctrl-Shift-J)
When it fails, does it running any of the script at all? Try stuffing some alert()s or console.log()s in there to see where the script is getting.
*Always* check the changelogs BEFORE updating that important software!
-
Greg01010100

Re: NoScript + Userscript Context Menu

Post by Greg01010100 »

Hi, barbaz, and thanks for helping! :)

I tried script you shown but it didn't helped.

Script works and was tested to work when site is allowed. I used Browser Console on few sites and here is what i got:

Code: Select all

JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0

JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
lpmanuallogins.length is 0


JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
lpmanuallogins.length is 0
JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
lpmanuallogins.length is 0
Thanks again for any help. :)
Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0
barbaz
Senior Member
Posts: 11143
Joined: Sat Aug 03, 2013 5:45 pm

Re: NoScript + Userscript Context Menu

Post by barbaz »

So nothing related errors... is that with site Allowed or Forbidden (or some of both)?

If you stick the line

Code: Select all

alert("Hi, I'm a running script!");
in various places in the code, do you ever get an alert? If so, at what point does it not fire (if any)? Does it fire outside the click event listener callback, what about inside?
*Always* check the changelogs BEFORE updating that important software!
-
Greg01010100

Re: NoScript + Userscript Context Menu

Post by Greg01010100 »

I tried adding that code you suggested and it fires only after I click button. Button doesn't even show itself in context menu till I allow site. Again thanks very much for taking time to help me. :)
Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0
barbaz
Senior Member
Posts: 11143
Joined: Sat Aug 03, 2013 5:45 pm

Re: NoScript + Userscript Context Menu

Post by barbaz »

Greg01010100 wrote:Button doesn't even show itself in context menu till I allow site.
Ah. Does it work for you instead use GM_registerMenuCommand which puts the menu item in the user script menu instead the context menu?
*Always* check the changelogs BEFORE updating that important software!
-
Greg01010100

Re: NoScript + Userscript Context Menu

Post by Greg01010100 »

Yeh it works if i use GM_registerMenuCommand
Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0
barbaz
Senior Member
Posts: 11143
Joined: Sat Aug 03, 2013 5:45 pm

Re: NoScript + Userscript Context Menu

Post by barbaz »

Sounds like all there is to do is not use the page context menu... Wonder if page context menu works with NoScript disabled completely from Add-ons Manager, and JavaScript disabled by about:config > javascript.enabled set to false ?
*Always* check the changelogs BEFORE updating that important software!
-
Greg01010100

Re: NoScript + Userscript Context Menu

Post by Greg01010100 »

No. If i disable NoScript and set javascript.enabled to false - context menu doesn't show up.........
Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0
barbaz
Senior Member
Posts: 11143
Joined: Sat Aug 03, 2013 5:45 pm

Re: NoScript + Userscript Context Menu

Post by barbaz »

Greg01010100 wrote:No. If i disable NoScript and set javascript.enabled to false - context menu doesn't show up.........
Thanks for testing that.
OK so not a NoScript issue, so the only way this will work with NoScript is if Giorgio decides to add some kind of work-around code in NoScript.
*Always* check the changelogs BEFORE updating that important software!
-
Greg01010100

Re: NoScript + Userscript Context Menu

Post by Greg01010100 »

Is there any way to notify him to consider extending userscript compatibility to make this work???
Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0
barbaz
Senior Member
Posts: 11143
Joined: Sat Aug 03, 2013 5:45 pm

Re: NoScript + Userscript Context Menu

Post by barbaz »

Note that it may not even be feasible, I said that only because Giorgio has added workarounds for these kinds of things before so it's not ruled out at this point.
Greg01010100 wrote:Is there any way to notify him to consider extending userscript compatibility to make this work???
If he doesn't respond in a week or so, if you like I'll do some testing and maybe PM him?
*Always* check the changelogs BEFORE updating that important software!
-
Post Reply