Closed Bug 1296636 Opened 9 years ago Closed 6 years ago

Bookmarklets don't work

Categories

(Firefox for iOS :: Home screen, defect, P1)

Other
iOS
defect

Tracking

()

RESOLVED FIXED
Tracking Status
fxios 16.0 ---

People

(Reporter: n, Assigned: justindarc)

References

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:50.0) Gecko/20100101 Firefox/50.0 Build ID: 20160818004001 Steps to reproduce: Attempted to run a simple bookmarklet that I created using my desktop Firefox client: `(function(){document.body.style.background='green';})()` Actual results: `javascript:`-prefixed string was sent as a query to my preferred search engine. Expected results: Javascript should have been executed in the current page context.
JavaScript cannot be run in Safari either. The difference is that Safari is displaying a warning message saying 'Cannot Run Script' while Firefox is sending 'javascript:;' to the default search engine. Stephan is there anything we can do here?
Flags: needinfo?(sleroux)
I've used bookmarklets on Safari for iOS for saving items to Pocket on iOS 7 so I'm not sure if Safari has removed the functionality or not but I doubt it. We should probably be able to support bookmarklets as well. From my understanding of the code, this might not be a bug necessarily but missing functionality. I'll throw this in our nomination list so we can start a conversation about it in the upcoming triage meeting.
tracking-fxios: --- → ?
Flags: needinfo?(sleroux)
Tracked in AHA-230
Priority: -- → P3
Bookmarklets definitely work on Safari, but just search for the contents on Firefox. I use the ‘Post to HN’ bookmarklet at https://news.ycombinator.com/bookmarklet.html regularly on Safari and would love to use it on Firefox too.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → INACTIVE

No-one’s working on this but it’s a valid bug that actively impedes my use of Fxvon iOS every day. Can someone reopen it?

Re-opening for consideration.

Status: RESOLVED → REOPENED
Resolution: INACTIVE → ---

(In reply to Robin Whittleton from comment #7)

No-one’s working on this but it’s a valid bug that actively impedes my use of Fxvon iOS every day. Can someone reopen it?

I can second that. It’s a daily problem for me.

+1 on this too. It's the only thing keeping me from switching over to Firefox.

Assignee: nobody → jdarcangelo
Status: REOPENED → ASSIGNED
Priority: P3 → --
Status: ASSIGNED → RESOLVED
Closed: 6 years ago6 years ago
Resolution: --- → FIXED
Priority: -- → P1

This appears to have regressed. Bookmarklets in F-for-iOS 19 are opening as search again.

Flags: needinfo?(fpatel)
Flags: needinfo?(gkeeley)

I put up a PR to fix the only problem I found which was that quotes were being replaced with fancy quotes: https://github.com/mozilla-mobile/firefox-ios/pull/5486

You can verify javascript: is currently working otherwise by doing javascript:alert()

Flags: needinfo?(gkeeley)
Flags: needinfo?(fpatel)

Right, I figured out what is wrong with the bookmark, and it's down to URL quoting, see below.

You can verify javascript: is currently working otherwise by doing javascript:alert()

The bookmark editor in FF iOS does not actually let you create such a bookmark, so testing was hampered (create a new bookmark, and you'll be given a URL-specific keyboard and URLs that start with javascript: are not accepted as the Save action remains disabled). I had previously used an existing JS bookmark that indeed uses quotes but was created on the desktop. A plain javascript:alert() bookmark created on the desktop then synched to iOS indeed works.

The following bookmark is opened as a search, however:

javascript:(function(){var a=Array.from(document.querySelectorAll("a[href$='.jpg']"), l => l.getAttribute('href'));a.sort();for(var i=0;i<a.length;i++){window.open(a[i]);}})()

This bookmark is designed to find all JPEG links and opens these in separate tabs (warning: popup blockers won't like this one, especially when there are many such images). The bookmark works fine on the desktop, is synched to iOS, then fails to work as expected on iOS FF.

I traced this to URL quoting; the above uses spaces and plenty of non-URL-safe characters. Here is the quoted version:

javascript:%28function%28%29%7Bvar%20a%3DArray.from%28document.querySelectorAll%28%22a%5Bhref%24%3D%27.jpg%27%5D%22%29%2C%20l%20%3D%3E%20l.getAttribute%28%27href%27%29%29%3Ba.sort%28%29%3Bfor%28var%20i%3D0%3Bi%3Ca.length%3Bi%2B%2B%29%7Bwindow.open%28a%5Bi%5D%29%3B%7D%7D%29%28%29

That one does work properly.

I appreciate the difference, I forgot entirely that as a URL you need to quote the non-URL-safe characters. Clearly, desktop FF doesn't care and handles quoting for us. The unexpected behaviour on iOS in this case is more that it is treated as a search, instead.

Should this be treated as a bug, and if so, should this be a separate, new ticket? Should the desktop behaviour be how iOS FF handles such bookmarks?

this pains me every day... however i seem to be getting different results, namely absolutely nothing happens when i click on bookmarklets. no search, nothing. not even javascript:alert() seems to work in for me. everything works fine in safari.

iPhone 6S
iOS: 13.3
Firefox 21.0 (16918)

this bug is making me consider switching back to chrome :o(

(In reply to Martijn Pieters from comment #14)

Should this be treated as a bug, and if so, should this be a separate, new ticket? Should the desktop behaviour be how iOS FF handles such bookmarks?

this should definitely be treated as a bug. bookmarklets work in all other iOS browsers i have tried (chrome and safari) as well as all desktop browsers. to me, and i bet many others, it is a very important feature.

This issue is being tracked here: https://github.com/mozilla-mobile/firefox-ios/issues/5626. Thank you for your feedback.

You need to log in before you can comment on or make changes to this bug.