Bug 188672 - Web Inspector: Provide $event in the console when paused on an event listener
Summary: Web Inspector: Provide $event in the console when paused on an event listener
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-08-16 13:02 PDT by Devin Rousso
Modified: 2019-03-20 13:31 PDT (History)
13 users (show)

See Also:


Attachments
Patch (16.99 KB, patch)
2018-08-16 13:59 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (17.58 KB, patch)
2019-03-18 19:22 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2018-08-16 13:02:36 PDT
* SUMMARY
When pausing on events, it's possible that the registered event listener might not have a parameter for the `event` object.

* TEST
    <script>
    document.body.addEventListnener("click", () => {
        debugger;
    });
    </script>

* STEPS TO REPRODUCE
1. Inspect test page
2. Add event breakpoint for "click"
3. Click anywhere within the page to pause
  => should be able to access the `event` value via `$event` even though there was no named parameter for it
Comment 1 Nikita Vasilyev 2018-08-16 13:43:54 PDT
Sounds like a good idea.

    $event = "foo";
    document.body.addEventListnener("click", () => {
        debugger;
    });

`$event` is defined, we should preserve it. E.g. show "foo" and not the click event object.
Comment 2 Devin Rousso 2018-08-16 13:59:52 PDT
Created attachment 347302 [details]
Patch
Comment 3 Joseph Pecoraro 2018-08-16 14:04:13 PDT
Comment on attachment 347302 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=347302&action=review

> Source/JavaScriptCore/inspector/InjectedScriptSource.js:1396
> +    this.$event = injectedScript._eventValue;

Given that events are a DOM concept, I don't think BasicCommandLineAPI will end up needing it. Since this is primarily for JSContext inspection (though it might make sense with ITMLKit inspection).

> Source/WebCore/inspector/CommandLineAPIModuleSource.js:50
> +    this.$event = injectedScript._eventValue;

I wonder if we can just make this something like:

    this.__defineGetter__("$event", () => inspectedWindow.event);

Is $event ever different from `window.event`? Yes it is possible for the page to have redefined the DOMWindow.prototype.event getter, so this isn't necessarily perfect but I don't think we need to be too concerned.
Comment 4 Joseph Pecoraro 2018-08-16 14:07:31 PDT
(In reply to Nikita Vasilyev from comment #1)
> Sounds like a good idea.
> 
>     $event = "foo";
>     document.body.addEventListnener("click", () => {
>         debugger;
>     });
> 
> `$event` is defined, we should preserve it. E.g. show "foo" and not the
> click event object.

Yes, this should be the normal behavior of the CommandLineAPI. The CommandLineAPI functions (keys, values, $0, $n, $exception, $event, etc) are in the background, so if the page has defined their own thing with an equivalent identifier, the page's thing should win out.
Comment 5 Devin Rousso 2018-08-16 16:20:23 PDT
Comment on attachment 347302 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=347302&action=review

>> Source/WebCore/inspector/CommandLineAPIModuleSource.js:50
>> +    this.$event = injectedScript._eventValue;
> 
> I wonder if we can just make this something like:
> 
>     this.__defineGetter__("$event", () => inspectedWindow.event);
> 
> Is $event ever different from `window.event`? Yes it is possible for the page to have redefined the DOMWindow.prototype.event getter, so this isn't necessarily perfect but I don't think we need to be too concerned.

I just tried this, and since `window.event` is defined, I'm not even sure that we need this.  Typing just `event` will give you the same result as `$event`.  I think we should hold off on this until we have a better reason for differentiating between `$event` and `event`/`window.event`.
Comment 6 Devin Rousso 2019-03-18 19:13:25 PDT
Comment on attachment 347302 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=347302&action=review

>>> Source/WebCore/inspector/CommandLineAPIModuleSource.js:50
>>> +    this.$event = injectedScript._eventValue;
>> 
>> I wonder if we can just make this something like:
>> 
>>     this.__defineGetter__("$event", () => inspectedWindow.event);
>> 
>> Is $event ever different from `window.event`? Yes it is possible for the page to have redefined the DOMWindow.prototype.event getter, so this isn't necessarily perfect but I don't think we need to be too concerned.
> 
> I just tried this, and since `window.event` is defined, I'm not even sure that we need this.  Typing just `event` will give you the same result as `$event`.  I think we should hold off on this until we have a better reason for differentiating between `$event` and `event`/`window.event`.

Considering that `window.event` is non-standard, and is more likely to be overridden by the page's JavaScript than `$event`, I think we should consider adding this.
Comment 7 Devin Rousso 2019-03-18 19:22:31 PDT
Created attachment 365110 [details]
Patch
Comment 8 WebKit Commit Bot 2019-03-19 12:31:36 PDT
Comment on attachment 365110 [details]
Patch

Clearing flags on attachment: 365110

Committed r243161: <https://trac.webkit.org/changeset/243161>
Comment 9 WebKit Commit Bot 2019-03-19 12:31:38 PDT
All reviewed patches have been landed.  Closing bug.
Comment 10 Radar WebKit Bug Importer 2019-03-19 12:32:16 PDT
<rdar://problem/49030174>
Comment 11 Truitt Savell 2019-03-20 09:52:58 PDT
The changes in https://trac.webkit.org/changeset/243161/webkit

has broken inspector/timeline/line-column.html

history:
http://webkit-test-results.webkit.org/dashboards/flakiness_dashboard.html#showAllRuns=true&tests=inspector%2Ftimeline%2Fline-column.html

I confirmed the test was working with the fix in 243155 and then broke in 243161 again.
Comment 12 Devin Rousso 2019-03-20 13:31:58 PDT
(In reply to Truitt Savell from comment #11)
> The changes in https://trac.webkit.org/changeset/243161/webkit
> 
> has broken inspector/timeline/line-column.html
> 
> history:
> http://webkit-test-results.webkit.org/dashboards/flakiness_dashboard.
> html#showAllRuns=true&tests=inspector%2Ftimeline%2Fline-column.html
> 
> I confirmed the test was working with the fix in 243155 and then broke in
> 243161 again.
Fixed test in followup <https://trac.webkit.org/changeset/243234/webkit>.