Closed Bug 1732559 Opened 4 years ago Closed 3 years ago

Setting focus() to an input Element in a popupwindow opened by a backgroundscript does not work

Categories

(Thunderbird :: Add-Ons: Extensions API, defect)

Thunderbird 91
defect

Tracking

(thunderbird_esr102+ fixed, thunderbird107 affected)

RESOLVED FIXED
108 Branch
Tracking Status
thunderbird_esr102 + fixed
thunderbird107 --- affected

People

(Reporter: G.Gersdorf, Assigned: john)

References

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0

Steps to reproduce:

Minimalistic Add-on:
==background.js:
async function start() {
let win=await messenger.windows.create({
url: "focus.html",
type: "popup",
});
}
start();
==focus.html
<!DOCTYPE html>
<html>
<head>
<script src="focus.js"></script>
<title>Focus Test</title>
</head>
<body>
<input id="email" type="text"/>
<input id="delay" type="number" min="0" max="10" size="2"/>
</body>
</html>
== focus.js
async function load() {
console.log('focus at start: '+document.activeElement.tagName);
let email=document.getElementById("email");
setTimeout(()=>{
email.focus();
console.log('focus now '+document.activeElement.tagName+' id='+document.activeElement.id);
}, 500);
}
document.addEventListener('DOMContentLoaded', load, { once: true });

Actual results:

Console output shows, that the focus is indeed on the correct element. But actually the text element is not highlighted and does not accept input.

Something interesting: If you click on one of the arrow icons of the number field, the text element now gets highlighted and accepts input.

Expected results:

The text element should be highlighted and accept input.

I can confirm the issue - can anyone take care?

Finally i've found the solution:
In addition to 'element.focus()' you need a 'window.focus()'.

Is this intended behaviour (since TB88) or is it still a bug?

In what order? First focus the window?

Seems to be irrelevant

Assignee: nobody → john
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true

Thanks Günter, I was finally able to get behind this due to your findings. The entire browser was not focused, so an focused element inside of it did not appear as focused.

Target Milestone: --- → 108 Branch

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/40fb5b228dfa
Set focus to extension browser, so focused elements will actually appear as focused. r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Depends on: 1797910

This has been broken again by https://phabricator.services.mozilla.com/D160172 but will be fixed by https://phabricator.services.mozilla.com/D160071.

I will add a test for this in Bug 1797910.

Comment on attachment 9299853 [details]
Bug 1732559 - Set focus to extension browser, so focused elements will actually appear as focused. r=mkmelin

[Approval Request Comment]
Regression caused by (bug #):
User impact if declined:
No focus on active elements after load of WebExtension page.

Testing completed (on c-c, etc.):
On Daily for more than 20 days, on Beta since merge day (14.11)

Risk to taking this patch (and alternatives if risky):
Low.

Attachment #9299853 - Flags: approval-comm-esr102?

Comment on attachment 9299853 [details]
Bug 1732559 - Set focus to extension browser, so focused elements will actually appear as focused. r=mkmelin

[Triage Comment]
Approved for esr102

Attachment #9299853 - Flags: approval-comm-esr102? → approval-comm-esr102+
Regressions: 1824036
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: