[e10s] Google Translator for Firefox add-on compatibility tracker

NEW
Unassigned

Status

()

Firefox
Extension Compatibility
P1
normal
2 years ago
3 months ago

People

(Reporter: Rakibul Islam Ratul, Unassigned, NeedInfo)

Tracking

(Depends on: 1 bug, Blocks: 1 bug)

unspecified
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(e10s+)

Details

(Whiteboard: [sitewait] triaged, URL)

(Reporter)

Description

2 years ago
Build ID: 20150519030202

not Worked in E10s mode but worked smoothly in non e10s mode. In E10s mode nor the selected text neither the full page translation is worked. Opposite scenery in non- e10s mode.
(Reporter)

Updated

2 years ago
Blocks: 905436
tracking-e10s: --- → +

Comment 1

2 years ago
[e10s tracking info]

Assignee: Giorgio Maone

Link to add-on: https://addons.mozilla.org/en-US/firefox/addon/google-translator-for-firefox/

Contact info for add-on: http://translatorforfirefox.blogspot.it/

Add-on ID: translator@zoli.bod

How well does it work?: 50%

Steps to reproduce working features:
* Right click on a non-English web page and choose "Translate selection with Google Translate" - no matter what you selected, a popup saying "The selected text may not be longer than 1100 characters!" will be shown instead of the expected translation

Any obvious performance problems? none

SDK-based: No, legacy XUL add-on

Chromium version: N/A (built-in Chrome feature)
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Windows 8.1 → All
Hardware: x86_64 → All
Summary: "Google Translator for Firefox" add-on does not work with e10s → [e10s] Google Translator for Firefox add-on compatibility tracker
Version: 41 Branch → unspecified
Giorgio, can you try to contact the author? I seem to recall you saying this one would be not too hard to convert.
Flags: needinfo?(g.maone)

Comment 3

2 years ago
The author seems to be very privacy-conscious, having no contact information (no email, no social pointers, no phone, nothing) listed on AMO and on his private websites.

Therefore I used the AMO editors dashboard to send him this "Request for more info" message:

Hi,

Thank you for your hard work on this useful add-on!
Unfortunately, it is broken by Electrolysis: therefore it will cease to work correctly in the stable Firefox versions likely by the end of this year. Please check https://bugzilla.mozilla.org/show_bug.cgi?id=1166434 for more details, and possibly CC yourself.

Fortunately, this kind of add-ons should be very easy to port on the Add-on SDK using high level APIs, or even to the new WebExtensions API, https://wiki.mozilla.org/WebExtensions . 
The former option would ensure your add-on a reasonable longevity, but the latter will stay around far longer and an early port of a popular add-on like yours would make for a great story encouraging our fellow developers.

Are you interested in either?

Thank you!
Flags: needinfo?(g.maone)
This might be a good candidate for WebExtensions.

Comment 5

2 years ago
Hi, I am nobzol, developer of the add-on. Sorry for the late answer, but I am very busy recently.

I am trying to catch up... so what version do I need to download to test Electrolysis?

Is it okay to start from https://wiki.mozilla.org/Electrolysis?

Thanks, Zoli

Comment 6

2 years ago
(In reply to nobzol from comment #5)

> I am trying to catch up... so what version do I need to download to test
> Electrolysis?

Either current Development Edition ( https://www.mozilla.org/en-US/firefox/developer/ ) or Nightly ( https://nightly.mozilla.org/ ).

For local testing you'll need to turn the "xpinstall.signatures.required" about:config preference to false.
 
> Is it okay to start from https://wiki.mozilla.org/Electrolysis?

Looking at your add-on we determined it should be very easy to port on the new WebExtensions API, so the best tarting point is https://wiki.mozilla.org/WebExtensions/

Be sure you read also https://wiki.mozilla.org/WebExtensions/FAQ

Feel free to contact me if you've got any doubt or need any help.

Comment 7

2 years ago
nobzol, any progress on this?
Flags: needinfo?(nobzol)

Comment 8

2 years ago
contactemail
Contacted Zoli by email.

Comment 9

2 years ago
Hi, I have finally started working on this. I am getting used to the new things, the main functions are operating now. However I have encountered some problems, so I have a few questions:
 1. how can I get the selected text from the active tab? Previously I could say document.commandDispatcher.focusedWindow.getSelection().toString();. Now as far as I know, the only thing that works now is window.getSelection().toString();, but this does not return the selected text if it is in either in an input field or textarea (or maybe in a frame but I have not tried that one). So how can I get the selected text from the focused element? Document.activeElement seems not to have getSelection() method.
 2. I have not dig myself into this really, but now it seems it is not possible to make a toolbar button, which has a little arrow next to it. All I could do is to make a popup, but I don't really want to do that, because it would slow down the workflow. Any workarounds for this one?
 3. And I have absolutely not tried this, but maybe there will be a problem, so I ask first. How does preferences reading/writing work these days? Previously there was Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.addonname."); for this, and then getBoolPref()/setBoolPref() etc. could be used on this object to read/write preferences. Is this still working, or is there something else I should use?

Thanks, and sorry for the slow progress.
Flags: needinfo?(nobzol)
(In reply to nobzol from comment #9)
> Hi, I have finally started working on this. I am getting used to the new
> things, the main functions are operating now.

It looks you've chosen not to go with the WebExtensions API, though.
Again, your extension looks pretty simple to port to this new framework, and you will need to do anyway, eventually, so I strongly advise you to start looking right now at https://developer.mozilla.org/en-US/Add-ons/WebExtensions

>  1. how can I get the selected text from the active tab? 

You need to use a content script ( https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts ), where you can use the common Web Platform API (i.e. window.getSelection(), primarily) to grab your text and send it to your background script in a message.

> input field or textarea (or maybe in a frame
> but I have not tried that one). So how can I get the selected text from the
> focused element? Document.activeElement seems not to have getSelection()
> method.

var el = document.activeElement;
var text = el && "value" in el && el.selectionEnd > el.selectionStart
  ? el.value.substring(el.selectionStart, el.selectionEnd)
  : "";



>  2. I have not dig myself into this really, but now it seems it is not
> possible to make a toolbar button, which has a little arrow next to it. All
> I could do is to make a popup, but I don't really want to do that, because
> it would slow down the workflow. Any workarounds for this one?

This is what we use in WebExtension: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/browserAction

If you've got some strong use case to extend this API in unsupported ways, we'll soon have a process in place to act on this kind of feedback / RFEs.

>  3. And I have absolutely not tried this, but maybe there will be a problem,
> so I ask first. How does preferences reading/writing work these days?

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage

Notice that the documentation above is still in progress and mainly generated automatically from Chrome's, so when in doubt refer also to https://developer.chrome.com/extensions and/or ask in IRC, #webextensions channel.

Comment 11

2 years ago
(In reply to Giorgio Maone from comment #10)
> (In reply to nobzol from comment #9)
> > Hi, I have finally started working on this. I am getting used to the new
> > things, the main functions are operating now.
> 
> It looks you've chosen not to go with the WebExtensions API, though.
> Again, your extension looks pretty simple to port to this new framework, and
> you will need to do anyway, eventually, so I strongly advise you to start
> looking right now at
> https://developer.mozilla.org/en-US/Add-ons/WebExtensions
Uhm, sorry, it was not clear in my message that I HAVE chosen to use the WebExtensions API. So my questions are related to it. There are some functions that I could port to the new API, but these I couldn't (yet).

> 
> >  1. how can I get the selected text from the active tab? 
> 
> You need to use a content script (
> https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts ),
> where you can use the common Web Platform API (i.e. window.getSelection(),
> primarily) to grab your text and send it to your background script in a
> message.
> 
> > input field or textarea (or maybe in a frame
> > but I have not tried that one). So how can I get the selected text from the
> > focused element? Document.activeElement seems not to have getSelection()
> > method.
> 
> var el = document.activeElement;
> var text = el && "value" in el && el.selectionEnd > el.selectionStart
>   ? el.value.substring(el.selectionStart, el.selectionEnd)
>   : "";
> 
Content<->Background script is OK, I've done it already, the problem is only with these special places. I will give a try to the lines above tonight, thanks.

> 
> 
> >  2. I have not dig myself into this really, but now it seems it is not
> > possible to make a toolbar button, which has a little arrow next to it. All
> > I could do is to make a popup, but I don't really want to do that, because
> > it would slow down the workflow. Any workarounds for this one?
> 
> This is what we use in WebExtension:
> https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/browserAction
> 
> If you've got some strong use case to extend this API in unsupported ways,
> we'll soon have a process in place to act on this kind of feedback / RFEs.
Yes, I did find this, and I'm already using it to place the icon, and it works ok. However, I did not find a way to place the small arrow, which opens up a list with some possibilities other than the main (instant translate) function: Options, Translate selected text and Translate full page. The source is currently not in front of me, maybe it was called menupopup in a toolboxbutton or something like this. Maybe is it possible to make a listener which listens to right-mouse-button? So the primary function would run if the button is clicked with left (primary) mouse button, and these extra functions would appear if right mouse button is clicked. This is not a very important function, but it would be nice.

> 
> >  3. And I have absolutely not tried this, but maybe there will be a problem,
> > so I ask first. How does preferences reading/writing work these days?
> 
> https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage
> 
> Notice that the documentation above is still in progress and mainly
> generated automatically from Chrome's, so when in doubt refer also to
> https://developer.chrome.com/extensions and/or ask in IRC, #webextensions
> channel.

Thanks, I will look at this.

And sorry again that I was not clear enough.

Updated

2 years ago
Depends on: 1244789

Comment 12

2 years ago
(In reply to nobzol from comment #11)
> (In reply to Giorgio Maone from comment #10)
> > (In reply to nobzol from comment #9)
> > > input field or textarea (or maybe in a frame
> > > but I have not tried that one). So how can I get the selected text from the
> > > focused element? Document.activeElement seems not to have getSelection()
> > > method.
> > 
> > var el = document.activeElement;
> > var text = el && "value" in el && el.selectionEnd > el.selectionStart
> >   ? el.value.substring(el.selectionStart, el.selectionEnd)
> >   : "";
> > 
> I will give a try to the lines above tonight,
> thanks.
This works for input and textarea fields, thank you (mostly because it seems, that my add-on does not do this currently... it did it some day, so it seems it went wrong some time in the past).

Anyway, it's not working in iframes. As I see, this must be a JavaScript limitation, as some quick tries on http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_document_activeelement ended with the same result: iframes don't get activeElement status. Maybe this was the reason for the existance of document.commandDispatcher.focusedWindow? Is there any way I can get the focused window (frame)? It's also good, if there is somewhere a getSelection() method which returns the Selection object which would be used if I pressed Ctrl+C. Maybe a "hack" using window.frames, and iterating through them (but how do I know which one is active). This one is kind of a "must have" request (not a "killer"), but a lot of people asked for this functionality earlier.

> > >  2. [...]small arrow[...]
Thanks for recording this as a bug. (1244789)

Thanks for the help, Zoli

Updated

2 years ago
Whiteboard: [sitewait]
(In reply to nobzol from comment #12)

> This works for input and textarea fields, thank you (mostly because it
> seems, that my add-on does not do this currently... it did it some day, so
> it seems it went wrong some time in the past).
> 
> Anyway, it's not working in iframes. As I see, this must be a JavaScript
> limitation, as some quick tries on
> http://www.w3schools.com/jsref/tryit.
> asp?filename=tryjsref_document_activeelement ended with the same result:
> iframes don't get activeElement status.

They do, you just need to use this recursive function to get the right element even if it's nested inside multiple (i)frames:

function findActiveIn(document) { 
  let active = document && document.activeElement;
  return active && active.contentWindow && findActiveIn(active.contentWindow.document) || active;
}

> > > >  2. [...]small arrow[...]
> Thanks for recording this as a bug. (1244789)
> 

No problem. Unfortunately it's not something that can be done overnight, and in facts that bug cannot block WebExtensions 1.0, where we need to reach Chrome parity as a priority before adding "big" divergent new features (which we definitely want to implement, though).

So, could you just please try to deliver a version with the level of UI currently allowed by WebExtensions / Chrome extensions (with the benefit of Chrome compatibility for free) and then "upgrade" it when Firefox supports a richer user experience which Chrome does not?

BTW, feel free to answer with your angle on https://bugzilla.mozilla.org/show_bug.cgi?id=1244789#c3
Flags: needinfo?(nobzol)
Reproduced with Ubuntu 14.04 (Mozilla/5.0 (X11; Linux i686; rv:48.0) Gecko/20100101 Firefox/48.0). 
Translate selection with Google Translate gives error (The selected text may not be longer than 1100 characters) when e10s is enabled. But the addon translates the same selection if e10s is disabled.

Comment 15

a year ago
750,000 users
Priority: -- → P1
Whiteboard: [sitewait] → [sitewait] triaged

Comment 16

11 months ago
(In reply to Rakibul Islam Ratul from comment #0)
> Build ID: 20150519030202
> 
> not Worked in E10s mode but worked smoothly in non e10s mode. In E10s mode
> nor the selected text neither the full page translation is worked. Opposite
> scenery in non- e10s mode.
Flags: sec-bounty?

Comment 17

11 months ago
(In reply to michaelzech81 from comment #16)
> (In reply to Rakibul Islam Ratul from comment #0)
> > Build ID: 20150519030202
> > 
> > not Worked in E10s mode but worked smoothly in non e10s mode. In E10s mode
> > nor the selected text neither the full page translation is worked. Opposite
> > scenery in non- e10s mode.

Comment 18

10 months ago
Hi!
I'm still working on this, but I progress really slow because of other stuff to do :(

So, I have a few questions:

1. Keyboard shortcuts / Hotkeys
1/a. Why are function keys (F1...F12) disallowed as a command hotkey? They were enabled before, and it's very annoying to be forced to live without this. It was VERY convenient to press F2, and the translation happened.
1/b. Is there any way to give the user an option to change the "suggested key"?
1/c. I need _execute_browser_action in commands API. Also, I need to get activeTab in chrome.commands.onCommand. Now, without this it's a pain to retrieve the active tab, I need a superfluous "tabs" permission to get the url of the active tab; and sometimes it's not even working.

2. Options page
2/a. How can I make a default for an option easily? --- Now, in my "background script" I have a code, that gets an option, and if it's undefined, it finds out some default value based on the FF settings (default target language for translations are based on chrome.i18n.getAcceptLanguages). I need exactly this on the options page; because I want to show the user the right value. How can I do this without code duplication?
2/b. What css should I include to make the Options part look the same on the Extension page, as the rest? (Big blue radio buttons, not-times-new-roman font and so.)
2/c. How can I migrate old-style preferences? They were visible in the about:config page, but I have not found anything that how can I access these. I need to access them somehow, to help the users with the same settings as they had before.

3. Context menu
3/a. Will "browser_action" value be enabled in contextMenus API? If I understand the documentation well, this would solve 1244789.
3/b. Is it possible to negate "contexts"? I need a context menu when there is a selection, and another when there isn't any. How can I do this? Somehow if I leave "selection" from contexts, the context menu also appears if there is a selection -- but in this case the 2 context menus are grouped under the name of the add-on.

4. Other
- How can I bring up an alert window, or anything else that can replace it in functionality?
- IFrame question: the code in https://bugzilla.mozilla.org/show_bug.cgi?id=1166434#c13 worked well at first, but now in F50 it throws an exception(?), or sets lastError(?) if the frame src is not the same as the page itselft (same origin-policy violation). How can I handle this nicely? Try-catch or something?

Thank you, Zoli

Comment 19

10 months ago
QA update:
Working as expected e10s enabled and disabled
Version 	51.0a2
Build ID 	20160929004005
User Agent 	Mozilla/5.0 (X11; Linux i686; rv:51.0) Gecko/20100101 Firefox/51.0
"ni" me if additional info or testing is needed
Flags: needinfo?(sescalante)
Flags: sec-bounty?

Updated

9 months ago
Flags: needinfo?(sescalante)

Comment 20

4 months ago
(In reply to nobzol from comment #18)
> 1. Keyboard shortcuts / Hotkeys
> 1/a. Why are function keys (F1...F12) disallowed as a command hotkey? They
> were enabled before, and it's very annoying to be forced to live without
> this. It was VERY convenient to press F2, and the translation happened.

I don't know, I will try to find this out and get back to you.

> 1/b. Is there any way to give the user an option to change the "suggested
> key"?

Note yet, but we plan on adding this. See bug 1303384 and bug 1348589.

> 1/c. I need _execute_browser_action in commands API. Also, I need to get
> activeTab in chrome.commands.onCommand. Now, without this it's a pain to
> retrieve the active tab, I need a superfluous "tabs" permission to get the
> url of the active tab; and sometimes it's not even working.

_execute_browser_action in commands API is supported since Firefox 52 (the current stable release).

> 
> 2. Options page
> 2/a. How can I make a default for an option easily? --- Now, in my
> "background script" I have a code, that gets an option, and if it's
> undefined, it finds out some default value based on the FF settings (default
> target language for translations are based on
> chrome.i18n.getAcceptLanguages). I need exactly this on the options page;
> because I want to show the user the right value. How can I do this without
> code duplication?

You can provide defaults to the storage API. If the key was not set before, then the defaults are used.
browser.storage.local.get({
   prefNameExample: 'prefValue',
   prefBoolExample: true,
}).then(function(items) {
   // Now do something with prefNameExample and prefBoolExample
});

See https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Implement_a_settings_page for another example.


> 2/b. What css should I include to make the Options part look the same on the
> Extension page, as the rest? (Big blue radio buttons, not-times-new-roman
> font and so.)

Since Firefox 55, you can use browser_style (this is not yet documented, but it was added in bug 1275287).

> 2/c. How can I migrate old-style preferences? They were visible in the
> about:config page, but I have not found anything that how can I access
> these. I need to access them somehow, to help the users with the same
> settings as they had before.

You can create an embedded WebExtension to migrate preferences. See https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Embedded_WebExtensions for documentation and examples.

> 3. Context menu
> 3/a. Will "browser_action" value be enabled in contextMenus API? If I
> understand the documentation well, this would solve 1244789.

Yes. This has already been supported since Firefox 53.

> 3/b. Is it possible to negate "contexts"? I need a context menu when there
> is a selection, and another when there isn't any. How can I do this? Somehow
> if I leave "selection" from contexts, the context menu also appears if there
> is a selection -- but in this case the 2 context menus are grouped under the
> name of the add-on.

This is not possible yet.
What you can do is to create a contextMenu that matches for both contexts, and in the onClicked handler perform different actions depending on whether there is a selection. With this method, your context menu item has the same menu item label for both actions though.
This Q&A might be useful to you: https://stackoverflow.com/questions/40564539/chrome-contextmenus-exclude-type

> 4. Other
> - How can I bring up an alert window, or anything else that can replace it
> in functionality?

If you want to show information, use the notifications API - https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/notifications.
If you want to show a popup, use browser.windows.create.
Alternatively, you can also use a content script to insert a styled notification in the current page (this only works if the add-on has the right host permission; also try to avoid information leakage and account for different styles across websites).

> - IFrame question: the code in
> https://bugzilla.mozilla.org/show_bug.cgi?id=1166434#c13 worked well at
> first, but now in F50 it throws an exception(?), or sets lastError(?) if the
> frame src is not the same as the page itselft (same origin-policy
> violation). How can I handle this nicely? Try-catch or something?

This is indeed a same-origin policy violation. You can use try-catch to catch it.
Alternatively, insert a content script in all frames from the background page (browser.tabs.executeScript with allFrames:true), collect the information and combine the pieces in the background page. If the information can be determined synchronously, then the results are simply available in the callback of tabs.executeScript. Otherwise (=asynchronously) you have to send the results using extension messaging (https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/onMessage)

Comment 21

3 months ago
(In reply to Rob Wu [:robwu] from comment #20)
> (In reply to nobzol from comment #18)
> > 1. Keyboard shortcuts / Hotkeys
> > 1/a. Why are function keys (F1...F12) disallowed as a command hotkey? They
> > were enabled before, and it's very annoying to be forced to live without
> > this. It was VERY convenient to press F2, and the translation happened.
> 
> I don't know, I will try to find this out and get back to you.

Function keys appear to be supported, since Firefox 53 (bug 1322033). So all blocking issues that you have mentioned so far have been fixed in the current stable version of Firefox :)
You need to log in before you can comment on or make changes to this bug.