Bug 235216 - Web Inspector: add a contextmenu item to create a URL Breakpoint for resources initiated by script
Summary: Web Inspector: add a contextmenu item to create a URL Breakpoint for resource...
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: 2022-01-13 19:28 PST by Devin Rousso
Modified: 2022-01-14 13:36 PST (History)
7 users (show)

See Also:


Attachments
Patch (10.36 KB, patch)
2022-01-13 19:30 PST, 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 2022-01-13 19:28:18 PST
this would also help expose the fact that URL Breakpoints exist :)
Comment 1 Devin Rousso 2022-01-13 19:30:46 PST
Created attachment 449127 [details]
Patch
Comment 2 Dean Jackson 2022-01-14 08:14:58 PST
Comment on attachment 449127 [details]
Patch

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

> Source/WebInspectorUI/UserInterface/Controllers/DOMDebuggerManager.js:470
> +            .filter((urlBreakpoint) => {

Is it normal style to wrap a single parameter in ()?

> Source/WebInspectorUI/UserInterface/Controllers/DOMDebuggerManager.js:487
> +                const typeRankings = [
> +                    WI.URLBreakpoint.Type.Text,
> +                    WI.URLBreakpoint.Type.RegularExpression,
> +                ];
> +                return typeRankings.indexOf(a.type) - typeRankings.indexOf(b.type);

This is cute.

> Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js:138
> +            contextMenu.appendItem(existingURLBreakpoints.length === 1 ? WI.UIString("Delete URL Breakpoint") : WI.UIString("Delete URL Breakpoints"), () => {

Do you really need === here, when checking against a literal number?

> Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js:140
> +                for (let urlBreakpoint of existingURLBreakpoints)
> +                    WI.domDebuggerManager.removeURLBreakpoint(urlBreakpoint);

Why not this shorter code?

existingURLBreakpoints.forEach(WI.domDebuggerManager.removeURLBreakpoint)
Comment 3 Devin Rousso 2022-01-14 13:09:47 PST
Comment on attachment 449127 [details]
Patch

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

Thanks for the review! =D

>> Source/WebInspectorUI/UserInterface/Controllers/DOMDebuggerManager.js:470
>> +            .filter((urlBreakpoint) => {
> 
> Is it normal style to wrap a single parameter in ()?

Technically it's not necessary, but it is Web Inspector style to always add the `(` `)` <https://trac.webkit.org/wiki/WebInspectorCodingStyleGuide#ArrowFunctions>

>> Source/WebInspectorUI/UserInterface/Controllers/DOMDebuggerManager.js:487
>> +                return typeRankings.indexOf(a.type) - typeRankings.indexOf(b.type);
> 
> This is cute.

:)

>> Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js:138
>> +            contextMenu.appendItem(existingURLBreakpoints.length === 1 ? WI.UIString("Delete URL Breakpoint") : WI.UIString("Delete URL Breakpoints"), () => {
> 
> Do you really need === here, when checking against a literal number?

Do you mean using `==` instead?  It's generally a bad idea to use `==` (even with a constant) in JS cause it doesn't also check the type (e.g. `"1" == 1` is true whereas `"1" === 1` is not).  The ESLint config for Web Inspector will warn you if you try to use `==` instead of `===` for that reason.

>> Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js:140
>> +                    WI.domDebuggerManager.removeURLBreakpoint(urlBreakpoint);
> 
> Why not this shorter code?
> 
> existingURLBreakpoints.forEach(WI.domDebuggerManager.removeURLBreakpoint)

We typically only use `forEach` when doing functional-style chaining.  Also, it makes it harder to find callsites of functions (and could possibly cause unintended side effects if the expected parameters of the passed in callback don't match `(item, index, array)`).  <https://trac.webkit.org/wiki/WebInspectorCodingStyleGuide#APIpreferences>
Comment 4 EWS 2022-01-14 13:35:53 PST
Committed r288029 (246055@main): <https://commits.webkit.org/246055@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 449127 [details].
Comment 5 Radar WebKit Bug Importer 2022-01-14 13:36:30 PST
<rdar://problem/87616390>