[FIXED] bookmarklets cannot add event listeners (Fx 27)

Bug reports and enhancement requests
porl
Posts: 18
Joined: Fri Mar 01, 2013 2:43 pm

[FIXED] bookmarklets cannot add event listeners (Fx 27)

Post by porl »

In Firefox 27.0 (Linux), a bookmarklet will no longer add an event listener to a document unless scripts are enabled for the host domain. This makes it impossible to navigate/modify a page using custom mouse or keyboard actions (zoom, drag, direction keys, etc) without a reload. NoScript 2.6.8.13 worked OK with the previous FF, but this behaviour breaks a large number of the bookmarklets I typically use, so I'm having to consider enabling all top-level domains.

No errors or indications are given.
Last edited by porl on Sun Mar 02, 2014 2:54 pm, edited 1 time in total.
Mozilla/5.0 (X11; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0
User avatar
therube
Ambassador
Posts: 7969
Joined: Thu Mar 19, 2009 4:17 pm
Location: Maryland USA

Re: NoScript prevents bookmarklet adding event listeners

Post by therube »

Example bookmarklet?
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball NoScript FlashGot AdblockPlus
Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 SeaMonkey/2.24
User avatar
Giorgio Maone
Site Admin
Posts: 9526
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: NoScript prevents bookmarklet adding event listeners

Post by Giorgio Maone »

I can confirm the change in behavior, which seems due to a change in Firefox's internals.
I'm not sure there's any work-around, but I'm looking for it.
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0
User avatar
Thrawn
Master Bug Buster
Posts: 3106
Joined: Mon Jan 16, 2012 3:46 am
Location: Australia
Contact:

Re: NoScript prevents bookmarklet adding event listeners

Post by Thrawn »

Can any of the bookmarklets be converted to surrogate scripts? If so, then you can make them run anywhere.

Generally it's just a matter of adding a new preference, noscript.surrogate.<arbitrary name>.sources, set to

Code: Select all

!@*
and then making a second, noscript.surrogate.<name>.replacement, containing the bookmarklet code.

You might even be able to combine multiple bookmarklets in one replacement, depending on how carefully they're written.
======
Thrawn
------------
Religion is not the opium of the masses. Daily life is the opium of the masses.

True religion, which dares to acknowledge death and challenge the way we live, is an attempt to wake up.
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0
porl
Posts: 18
Joined: Fri Mar 01, 2013 2:43 pm

Re: NoScript prevents bookmarklet adding event listeners

Post by porl »

Thrawn wrote:Can any of the bookmarklets be converted to surrogate scripts?
Thanks, Thrawn, that sounds like a good idea for some of my regular haunts.

On the other hand, I quite often use bookmarklets to modify a page for printing: click to delete page content I don't want printed and put what remains in as tiny a font as I can, so a technical article doesn't run to tens of pages.

In that case I won't know in advance what I want to print and I would prefer not to add that functionality to every site I encounter, however carefully I try to package it.

@therube: I have other uses for event listeners, but the 'click to delete' feature is a good example. At its simplest:

Code: Select all

  (function () {
    document.addEventListener('click', function (ev) {
      var el = ev.target;
      if (el.nodeType == 1 && confirm('Delete ' + el.tagName + '?')) {
        el.parentNode.removeChild(el);
        ev.stopPropagation();
        ev.preventDefault();
      }
    }, false);
  })()
(with that whitespace, run this in Scratchpad). I've just noticed, NoScript prevents the code running in Scratchpad too unless the domain is allowed scripting.
Mozilla/5.0 (X11; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0
User avatar
Giorgio Maone
Site Admin
Posts: 9526
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: NoScript prevents bookmarklet adding event listeners

Post by Giorgio Maone »

Worked around in latest development build 2.6.8.15rc1.

Notice that I cannot do anything about Scratchpad, WebConsole, Firebug etc., though, because it's been a Firefox JavaScript runtime change rather than a NoScript change: in facts, you can observe the same "regression" also without NoScript, if you just set the javascript.enabled about:config preference to false. I suppose they can either revert the change, if it's not a security issue, or use the same work-around as mine in the places where it's needed, but I suppose bug reports in their own bug trackers are required.
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0
porl
Posts: 18
Joined: Fri Mar 01, 2013 2:43 pm

Re: NoScript prevents bookmarklet adding event listeners

Post by porl »

Giorgio Maone wrote:Worked around in latest development build 2.6.8.15rc1.
Sorry, Giorgio, I'm not seeing any difference with that version.
Mozilla/5.0 (X11; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0
User avatar
Giorgio Maone
Site Admin
Posts: 9526
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: bookmarklets cannot add event listeners

Post by Giorgio Maone »

You're right, I'm not sure why but it seemed to work for me at some stage.
Investigating, but it seems really hard to work-around: looks like they previously checked disablement status only on direct execution script, but now they also do it before running delayed listeners.
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0
User avatar
Thrawn
Master Bug Buster
Posts: 3106
Joined: Mon Jan 16, 2012 3:46 am
Location: Australia
Contact:

Re: NoScript prevents bookmarklet adding event listeners

Post by Thrawn »

porl wrote:
Thrawn wrote:Can any of the bookmarklets be converted to surrogate scripts?
Thanks, Thrawn, that sounds like a good idea for some of my regular haunts.

On the other hand, I quite often use bookmarklets to modify a page for printing: click to delete page content I don't want printed and put what remains in as tiny a font as I can, so a technical article doesn't run to tens of pages.

In that case I won't know in advance what I want to print and I would prefer not to add that functionality to every site I encounter, however carefully I try to package it.
Well, you might be able to adjust the bookmarklet code to become the onclick handler of a link that the surrogate inserts into the page...
But really this is more of use case for a proper extension. It's not all that hard to get started with one.
======
Thrawn
------------
Religion is not the opium of the masses. Daily life is the opium of the masses.

True religion, which dares to acknowledge death and challenge the way we live, is an attempt to wake up.
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0
User avatar
Giorgio Maone
Site Admin
Posts: 9526
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: bookmarklets cannot add event listeners anymore (Fx 27)

Post by Giorgio Maone »

Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0
User avatar
Giorgio Maone
Site Admin
Posts: 9526
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: bookmarklets cannot add event listeners anymore (Fx 27)

Post by Giorgio Maone »

Please check latest development build rc2, thank you!
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0
User avatar
Thrawn
Master Bug Buster
Posts: 3106
Joined: Mon Jan 16, 2012 3:46 am
Location: Australia
Contact:

Re: bookmarklets cannot add event listeners anymore (Fx 27)

Post by Thrawn »

So this broke all the built-in surrogates too?

Mozilla really needs to consult the Mozilla Security Group before making changes...oh, wait, that's 404 these days, isn't it?
======
Thrawn
------------
Religion is not the opium of the masses. Daily life is the opium of the masses.

True religion, which dares to acknowledge death and challenge the way we live, is an attempt to wake up.
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0
User avatar
Giorgio Maone
Site Admin
Posts: 9526
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: bookmarklets cannot add event listeners anymore (Fx 27)

Post by Giorgio Maone »

Thrawn wrote:So this broke all the built-in surrogates too?
Nope, only those which used to register event listeners, i.e. none of the built-ins, fortunately.
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0
porl
Posts: 18
Joined: Fri Mar 01, 2013 2:43 pm

Re: bookmarklets cannot add event listeners anymore (Fx 27)

Post by porl »

Giorgio Maone wrote:Please check latest development build rc2, thank you!
I'll test it some more over coming days, but it looks like you've solved not only this issue, but http://forums.informaction.com/viewtopi ... 10&t=13040 too, which is great news.

Many thanks.
Mozilla/5.0 (X11; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0
porl
Posts: 18
Joined: Fri Mar 01, 2013 2:43 pm

Re: bookmarklets cannot add event listeners anymore (Fx 27)

Post by porl »

Full marks for re-enabling eventListeners/XHRs but a couple of things are, sadly, lost along the way.

Bookmarklets enabled by NoScript in the new way
- can't return a string of HTML:

Code: Select all

javascript:'<h3>'+new Date()+'</h3>'
- can't use document.write()

This makes it impossible to achieve some things that are really useful, like writing an IFRAME to show the current document alongside something else. The DOM simply won't do this.

It also complicates using a document as an alternative to the console.

These features can only be restored by enabling scripts globally, so the eventListener/XHR problem had less impact on security.

Also it seems Firefox displays neither syntax nor runtime errors for javascript typed into the address bar.

A couple of other small points:

Firefox doesn't properly URL-encode bookmarklets, so the call to decodeURIComponent() at line 4361 of noscriptService.js:

Code: Select all

  ScriptSurrogate.executeSandbox(window.document,
    decodeURIComponent(url.substring("javascript:".length)));
gives 'malformed URI sequence' errors on bookmarklets that contain '%'s that weren't (manually) escaped. You could test for

Code: Select all

/%[0-9A-F]2/i
before doing that call, because a user may have escaped some '%'s to avoid syntax errors.

Incidentally, I notice the alert text for 'Allow Scripts Globally' contains "\\n" instead of "\n".
Mozilla/5.0 (X11; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0
Post Reply