<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>20713</bug_id>
          
          <creation_ts>2013-01-20 12:03:19 +0000</creation_ts>
          <short_desc>Consider defining window.event and Event.srcElement</short_desc>
          <delta_ts>2016-09-27 13:35:37 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>DOM</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>MOVED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard>blocked on implementers weighing in</status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ms2ger">Ms2ger</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>bugs</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>mike</cc>
    
    <cc>philipj</cc>
    
    <cc>w3bugs</cc>
    
    <cc>www-dom</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>81605</commentid>
    <comment_count>0</comment_count>
    <who name="Ms2ger">Ms2ger</who>
    <bug_when>2013-01-20 12:03:19 +0000</bug_when>
    <thetext>See &lt;https://bugzilla.mozilla.org/show_bug.cgi?id=453968&gt;. At least in WebKit, it appears to be identical to Event.target.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81628</commentid>
    <comment_count>1</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-01-21 12:11:43 +0000</bug_when>
    <thetext>So what about window.event?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81629</commentid>
    <comment_count>2</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-01-21 12:52:15 +0000</bug_when>
    <thetext>(&quot;event&quot; in window) is true in Chrome and in Opera too I believe. Adding event.srcElement without window.event seems risky.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84921</commentid>
    <comment_count>3</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-03-25 13:01:54 +0000</bug_when>
    <thetext>SVG also contributes to this: https://bugzilla.mozilla.org/show_bug.cgi?id=854213</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85005</commentid>
    <comment_count>4</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-03-26 10:22:02 +0000</bug_when>
    <thetext>Chrome is going to investigate removing this: https://code.google.com/p/chromium/issues/detail?id=223749</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100499</commentid>
    <comment_count>5</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-02-13 11:27:56 +0000</bug_when>
    <thetext>The WindowEvent counter in Chrome was 7.641600241 :-( However, we still haven&apos;t added anything to Gecko...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116593</commentid>
    <comment_count>6</comment_count>
    <who name="Philip Jägenstedt">philipj</who>
    <bug_when>2014-12-19 23:31:21 +0000</bug_when>
    <thetext>Event.srcElement is around 20%:
https://www.chromestatus.com/metrics/feature/timeline/popularity/343

It&apos;s just an alias of target, so adding that seems like the only way to go.

Window.event is around 4% now:
https://www.chromestatus.com/metrics/feature/timeline/popularity/69

https://code.google.com/p/chromium/issues/detail?id=223749#c3 says that &quot;Inline event handlers have a local `event` binding in scope.&quot; but I&apos;m not sure if that&apos;s how it works in Blink. However it works, stuff like onclick=&quot;event.target.style.color=&apos;red&apos;&quot; has to work.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116605</commentid>
    <comment_count>7</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-12-20 10:01:52 +0000</bug_when>
    <thetext>(In reply to Philip Jägenstedt from comment #6)
&gt; Event.srcElement is around 20%:
&gt; https://www.chromestatus.com/metrics/feature/timeline/popularity/343
&gt; 
&gt; It&apos;s just an alias of target, so adding that seems like the only way to go.

This seems very similar to the isSameNode() situation as Mozilla never added it. If Mozilla wants to add this, we should probably define it, along with window.event as I believe they cannot be decoupled.


&gt; Window.event is around 4% now:
&gt; https://www.chromestatus.com/metrics/feature/timeline/popularity/69
&gt; 
&gt; https://code.google.com/p/chromium/issues/detail?id=223749#c3 says that
&gt; &quot;Inline event handlers have a local `event` binding in scope.&quot; but I&apos;m not
&gt; sure if that&apos;s how it works in Blink. However it works, stuff like
&gt; onclick=&quot;event.target.style.color=&apos;red&apos;&quot; has to work.

event.target can work by putting that in the local scope, you don&apos;t need a global property for that to work per se.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116612</commentid>
    <comment_count>8</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2014-12-20 13:29:52 +0000</bug_when>
    <thetext>(In reply to Anne from comment #7)
&gt; (In reply to Philip Jägenstedt from comment #6)
&gt; &gt; Event.srcElement is around 20%:
&gt; &gt; https://www.chromestatus.com/metrics/feature/timeline/popularity/343
&gt; &gt; 
&gt; &gt; It&apos;s just an alias of target, so adding that seems like the only way to go.
&gt; 
&gt; This seems very similar to the isSameNode() situation as Mozilla never added
&gt; it. If Mozilla wants to add this, we should probably define it, along with
&gt; window.event as I believe they cannot be decoupled.

I haven&apos;t heard recently anyone asking us to add  window.event or Event.srcElement.
I&apos;d expect adding window.event to actually break things (when using Gecko), since at least at some point there were pages doing 
if (window.event) {
  // some more IE-style stuff
}
Not sure how blink copes with that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116618</commentid>
    <comment_count>9</comment_count>
    <who name="Philip Jägenstedt">philipj</who>
    <bug_when>2014-12-21 00:57:03 +0000</bug_when>
    <thetext>(In reply to Anne from comment #7)
&gt; (In reply to Philip Jägenstedt from comment #6)
&gt; &gt; Event.srcElement is around 20%:
&gt; &gt; https://www.chromestatus.com/metrics/feature/timeline/popularity/343
&gt; &gt; 
&gt; &gt; It&apos;s just an alias of target, so adding that seems like the only way to go.
&gt; 
&gt; This seems very similar to the isSameNode() situation as Mozilla never added
&gt; it. If Mozilla wants to add this, we should probably define it, along with
&gt; window.event as I believe they cannot be decoupled.

What&apos;s the connection between Window.event and Event.srcElement other than being IE-isms?

&gt; &gt; Window.event is around 4% now:
&gt; &gt; https://www.chromestatus.com/metrics/feature/timeline/popularity/69
&gt; &gt; 
&gt; &gt; https://code.google.com/p/chromium/issues/detail?id=223749#c3 says that
&gt; &gt; &quot;Inline event handlers have a local `event` binding in scope.&quot; but I&apos;m not
&gt; &gt; sure if that&apos;s how it works in Blink. However it works, stuff like
&gt; &gt; onclick=&quot;event.target.style.color=&apos;red&apos;&quot; has to work.
&gt; 
&gt; event.target can work by putting that in the local scope, you don&apos;t need a
&gt; global property for that to work per se.

It looks like window.event is undefined in Blink/WebKit/IE when no event is firing, but &apos;event&apos; in window is always true. What does it mean to put event in the local scope? Something like &quot;arguments&quot; in function calls?

I have no data to back this up, but it seems wise to ensure that this works:

function handle() {
  event.target.style.color = &apos;red&apos;;
}

onclick=&quot;handle()&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116623</commentid>
    <comment_count>10</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-12-21 18:25:59 +0000</bug_when>
    <thetext>I think it means that if you lookup &quot;event&quot; that it&apos;s found on the environment record. So yes, that example should work. As for srcElement and window.event, I remember a conclusion that they were coupled based on some examination of code. Perhaps that changed...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116625</commentid>
    <comment_count>11</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2014-12-21 18:29:37 +0000</bug_when>
    <thetext>(In reply to Philip Jägenstedt from comment #9)
&gt; I have no data to back this up, but it seems wise to ensure that this works:

Why it would be wise?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116630</commentid>
    <comment_count>12</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2014-12-21 20:18:45 +0000</bug_when>
    <thetext>&gt; So yes, that example should work.

Why would it?  It doesn&apos;t work in Gecko, and we have no evidence that the web depends on it.

I share Olli&apos;s concern about adding window.event.  I expect it&apos;s common for people to pull in other nonstandard stuff that IE had and WebKit copied if that&apos;s defined.

I have some questions about the data here, though.

&gt; Event.srcElement is around 20%:

How many of those are:

  var target = event.srcElement || event.target;

?

&gt; Window.event is around 4% now:

Again, do we have any data on what the uses look like?

&gt; This seems very similar to the isSameNode()

No, it&apos;s very different, because we know for a fact people use at least window.event for browser detection, so implementing it in Gecko carries huge compat risks which are not present with implementing isSameNode.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116638</commentid>
    <comment_count>13</comment_count>
    <who name="Philip Jägenstedt">philipj</who>
    <bug_when>2014-12-22 08:14:44 +0000</bug_when>
    <thetext>(In reply to Olli Pettay from comment #11)
&gt; (In reply to Philip Jägenstedt from comment #9)
&gt; &gt; I have no data to back this up, but it seems wise to ensure that this works:
&gt; 
&gt; Why it would be wise?

It&apos;s a mutation of the code in comment #6 that seems almost certain to have happened. If others don&apos;t share that hunch, then we&apos;d need actual data.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116639</commentid>
    <comment_count>14</comment_count>
    <who name="Philip Jägenstedt">philipj</who>
    <bug_when>2014-12-22 09:20:25 +0000</bug_when>
    <thetext>(In reply to Boris Zbarsky from comment #12)
&gt; &gt; So yes, that example should work.
&gt; 
&gt; Why would it?  It doesn&apos;t work in Gecko, and we have no evidence that the
&gt; web depends on it.
&gt; 
&gt; I share Olli&apos;s concern about adding window.event.  I expect it&apos;s common for
&gt; people to pull in other nonstandard stuff that IE had and WebKit copied if
&gt; that&apos;s defined.

Which specific other IE-isms are you concerned about? We should either standardize or remove them, and if deemed necessary due to entanglement they could be done in a batch.

&gt; I have some questions about the data here, though.
&gt; 
&gt; &gt; Event.srcElement is around 20%:
&gt; 
&gt; How many of those are:
&gt; 
&gt;   var target = event.srcElement || event.target;
&gt; 
&gt; ?
&gt;
&gt; &gt; Window.event is around 4% now:
&gt; 
&gt; Again, do we have any data on what the uses look like?

The use counter data can&apos;t answer either of these questions. My only idea for answering questions like these would be to check how often Event.srcElement but not Event.target is accessed in a script run (event handler, setTimeout, etc.) Even that wouldn&apos;t be conclusive, so I haven&apos;t tried to add the scaffolding to make it possible.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116645</commentid>
    <comment_count>15</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2014-12-22 19:33:16 +0000</bug_when>
    <thetext>&gt; It&apos;s a mutation of the code in comment #6 that seems almost certain to have
&gt; happened.

It has, in the past, but it&apos;s common knowledge that this doesn&apos;t work in Firefox, so people are a bit more careful now.

&gt; Which specific other IE-isms are you concerned about?

I&apos;ve seen people assume all sorts of things if window.event over the years.  What they assume right now is something we&apos;d need data on.

&gt; We should either standardize or remove them

Sounds nice, depending on what they are.  Just watch out for the assumptions being ones we can&apos;t do either one with, like some of the irreconcilable differences in ES behavior (e.g. around handling of function declarations inside conditionals).

What&apos;s needed is data.  Assuming we want to go in this direction, of course.  It may actually be simpler to remove window.event from all UAs than to get sufficient data on what breaks if it&apos;s added and what other crud then has to become part of the web platform forever.

Note that we haven&apos;t even started the conversation about what behavior window.event should have, which is not at all obvious to me either.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121781</commentid>
    <comment_count>16</comment_count>
    <who name="Philip Jägenstedt">philipj</who>
    <bug_when>2015-07-06 09:04:22 +0000</bug_when>
    <thetext>Some things from the Blink bug:
https://code.google.com/p/chromium/issues/detail?id=223749

First, the use counter is over 3%:
https://www.chromestatus.com/metrics/feature/timeline/popularity/69

That cannot be an accurate estimate of the risk of removing window.event in Blink, so we need better data. Is the only case worth measuring when window.event is non-undefined while accessed from a non-inline event listener, like in this following?

x.addEventListener(&apos;click&apos;, function() {
  if (event.type == &apos;foo&apos;)
    bar();
});

Also, I learned that there&apos;s a difference between SVG and HTML:
https://code.google.com/p/chromium/issues/detail?id=223749#c10

Of the three end states mentioned there, does any seem more worth aiming for, or are there other, better, end states?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121800</commentid>
    <comment_count>17</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-07-06 09:37:48 +0000</bug_when>
    <thetext>It&apos;s not clear to me what the constraints are on SVG (perhaps both &quot;evt&quot; and &quot;event&quot; can be exposed as variables in the event handler scope?), but I don&apos;t think it should have any bearing on whether or not to keep window.event.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121805</commentid>
    <comment_count>18</comment_count>
    <who name="Philip Jägenstedt">philipj</who>
    <bug_when>2015-07-06 12:21:59 +0000</bug_when>
    <thetext>It does add the risk things like onload=&quot;StartAnimation(event)&quot; in SVG into the mix.

If we assume that nothing about inline event handlers will change, what kind of data do we need to move this along? To put it another way, what kind of breakage is most likely if Gecko adds window.event and if Blink removes window.event, respectively?

I&apos;m still not sure about the connection between Window.event and Event.srcElement, see comment #9. It sounds like IE-sniffing on the form `&apos;event&apos; in window` or `window.event` (inside an event handler) are the main concerns.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121822</commentid>
    <comment_count>19</comment_count>
    <who name="Philip Jägenstedt">philipj</who>
    <bug_when>2015-07-06 15:19:42 +0000</bug_when>
    <thetext>I found the source of window.event in WebKit/Blink:
https://projects.kde.org/projects/kde/kdelibs/repository/revisions/f7067e7d6d17aeece5d8bf4b12b73ae8af7c8f9a

&quot;&quot;&quot;
Discussing with tobias, we found a nice and easy way to implement &quot;window.event&quot;.
JSEventListener::handleEvent simply sets the event in the Window object,
and from there we use Peter&apos;s magic (getDOMEvent()).
This would fix #30780 if there wasn&apos;t a bug in the script itself :(
&quot;&quot;&quot;

The bug was https://bugs.kde.org/show_bug.cgi?id=30780 with reference to this site:
http://web.archive.org/web/20010813082633/http://azzuma.com/HTML/antinea.html

I don&apos;t know if the local binding for inline event listeners existed at the time.

All in all, this didn&apos;t reveal anything interesting about the compat situation.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127546</commentid>
    <comment_count>20</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2016-09-27 13:35:37 +0000</bug_when>
    <thetext>Now discussing this here together with other Microsoft extensions: https://github.com/whatwg/dom/issues/334.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>