If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

document.activeElement is not pointing to the focused textarea/input



Add-on SDK
5 years ago
5 years ago


(Reporter: navaneethkn, Assigned: ochameau)


Firefox Tracking Flags

(Not tracked)



(1 attachment)



5 years ago
Created attachment 702672 [details]
Sample addon showing the problem

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:18.0) Gecko/20100101 Firefox/18.0
Build ID: 20130104151948

Steps to reproduce:

I have an addon which creates a context menu item for all textareas and input controls. When user clicks on the menu item, my content script will hook up keydown event to the activeElement. In all pages I am getting the activeElement properly. But in some pages this activeElement is not pointing to the textarea/input which is in focus. Running document.activeElement from firebug console works well. But not from addon's content script. 

To reproduce
1 - Download the attached same addon
2 - cfx run
3 - Goto gmail.com and login
4 - Right click on the top search bar and choose an item from "My addon" menu
5 - Observe the console output. Console output will say activeElement not found. Even document.getElementById is also not working in this case

Actual results:

document.activeElement is not pointing the focused control

Expected results:

document.activeElement should have pointed to the textarea/input where the focus is

Comment 1

5 years ago
I have created a Gist which has the two files for easiness. Please take a look at

What version of the SDK are you testing this with?
Flags: needinfo?(navaneethkn)

Comment 3

5 years ago
(In reply to Wes Kocher (:KWierso) from comment #2)
> What version of the SDK are you testing this with?

Add-on SDK 1.12 (9c31911385c15801523dd6ca27bcc2a5748ff476)
Flags: needinfo?(navaneethkn)
Alex, can you try to reproduce this and see what's going on?
Assignee: nobody → poirot.alex
Priority: -- → P3

Comment 5

5 years ago
Looks like adding

attachTo: ['existing', 'top']

to the pageMod solved this issue. Not sure why this happens though.

Comment 6

5 years ago
The gist works fine for me. But I think that you were mostly tricked by the execution of your page-mod content script on all gmail iframe.
And that is the reason why you don't see this issue when using `attachTo: ['existing', 'top']` as it will prevent applying content script to iframe so that you will now have only one content script per tab.
Last Resolved: 5 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.