Closed Bug 1717760 Opened 3 years ago Closed 3 years ago

initKeyEvent on KeyboardEvent should return undefined

Categories

(Core :: DOM: Events, enhancement, P3)

Firefox 91
enhancement

Tracking

()

RESOLVED FIXED
93 Branch
Webcompat Priority P1
Tracking Status
firefox89 --- wontfix
firefox90 --- wontfix
firefox91 --- wontfix
firefox92 --- wontfix
firefox93 --- fixed

People

(Reporter: karlcow, Assigned: masayuki)

References

(Blocks 1 open bug, )

Details

(Keywords: dev-doc-complete)

Attachments

(2 files)

Test

var i = document.createEvent("KeyboardEvent");
typeof i.initKeyEvent;

On Firefox it returns function
On Blink and WebKit browsers, it returns undefined

This creates at least a webcompat issue on startrack.com.au

Given that it is not implemented in Safari, Chrome and Edge, I have the feeling we can safely unship it. We could try on Nightly, and discover if any sites break.

I see Masayuki mentioning initKeyEvent() in Bug 1479964 Comment #25

I wonder if it's the relevant code.
https://searchfox.org/mozilla-central/rev/f351e19360729b351bfc7c1386d6e4ca4ea676e2/dom/events/KeyboardEvent.cpp#313-328

It's also not specified in the DOM Specification.
https://dom.spec.whatwg.org/

And defined as non standard and deprecated on MDN
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyEvent

Masayuki, do you want to take this? I would suggest we add a preference that's false-by-default and use that to hide the method in IDL. Then if we don't notice anything we can remove it entirely after a couple of releases. Let's also do an intent to unship just in case.

Flags: needinfo?(masayuki)
Keywords: dev-doc-needed

Hmm, it's an old API, so, I bet that there are some web apps in the wild which use it for detecting Firefox...

Assignee: nobody → masayuki
Status: NEW → ASSIGNED
Flags: needinfo?(masayuki)
Severity: -- → S3
Type: defect → enhancement
OS: Windows 10 → All
Priority: -- → P3
Hardware: Unspecified → All

122,392 code results

https://github.com/search?q=initKeyEvent&type=Code
sigh... perhaps, we should do it with an allowed list, isn't it?

I'm not sure what that means? A lot of the code there seems to make usage conditional though and uses initKeyboardEvent() if not available, which is something all browsers expose.

Yeah, I do see some code that calls initKeyEvent without existence check but those are just a few, and others are mostly from happen.js and jquery.simulate.js that have workarounds.

Okay, I'll post a patch which just disables it with a pref.

Now, Gecko is the only browser to support undocumented KeyEvent.initKeyEvent.
We should drop it by default because typeof KeyboardEvent.initKeyEvent is
used at least in a major web-site and which causes not working the web-site.

Depends on D121028

The webcompat team will watch out if there is new breakage where initKeyEvent would be used to identify/target Firefox.

Pushed by masayuki@d-toybox.com:
https://hg.mozilla.org/integration/autoland/rev/2ee20e58b0f1
Stop using `KeyEvent.initKeyEvent` in our tests r=smaug
https://hg.mozilla.org/integration/autoland/rev/81a7baecf0cb
Disable `KeyEvent.initKeyEvent` by default r=smaug
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/29963 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 93 Branch
Regressions: 1724925
Upstream PR merged by moz-wptsync-bot

Since the status are different for nightly and release, what's the status for beta?
For more information, please visit auto_nag documentation.

We just emailed affected developers to let them know .initKeyEvent is deprecated as of Firefox 93 and will be unshipped in Firefox 96.

FYI FF93 MDN docs for this can be tracked in https://github.com/mdn/content/issues/8623. This is just addition of release note, and making information about the deprecation and the preference more clear on the page.
When you actually remove it we'll need to do a little more work in cleanup.

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

Attachment

General

Created:
Updated:
Size: