Changeset 288029 in webkit


Ignore:
Timestamp:
Jan 14, 2022 1:34:39 PM (6 months ago)
Author:
Devin Rousso
Message:

Web Inspector: add a contextmenu item to create a URL Breakpoint for resources initiated by script
https://bugs.webkit.org/show_bug.cgi?id=235216

Reviewed by Dean Jackson.

  • UserInterface/Views/ContextMenuUtilities.js:

(WI.appendContextMenuItemsForSourceCode):
Since URL Breakpoints only work with XHR/fetch, only offer to create a URL Breakpoint if
the WI.SourceCode has initiatorCallFrames, meaning it was triggered by JS. We could
offer this contextmenu item for _all_ resources, but there are many different resource types
that are unlikely (if ever) to be loaded via XHR/fetch (e.g. favicons, manifests, fonts,
initial JS/CSS files, etc.) that it would likely add clutter and possibly confuse developers
into thinking that URL Breakpoints can somehow pause things other than JS. Plus, this can
always be changed in a followup, so better to do something minimal first.

  • UserInterface/Controllers/DOMDebuggerManager.js:

(WI.DOMDebuggerManager.prototype.urlBreakpointsMatchingURL): Added.
Helper method to find all WI.URLBreakpoint that match a given URL, sorted by how exact
they would match (e.g. a regex match is less exact than ===).

  • Localizations/en.lproj/localizedStrings.js:
Location:
trunk/Source/WebInspectorUI
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r287999 r288029  
     12022-01-14  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: add a contextmenu item to create a URL Breakpoint for resources initiated by script
     4        https://bugs.webkit.org/show_bug.cgi?id=235216
     5
     6        Reviewed by Dean Jackson.
     7
     8        * UserInterface/Views/ContextMenuUtilities.js:
     9        (WI.appendContextMenuItemsForSourceCode):
     10        Since URL Breakpoints only work with XHR/`fetch`, only offer to create a URL Breakpoint if
     11        the `WI.SourceCode` has `initiatorCallFrames`, meaning it was triggered by JS. We could
     12        offer this contextmenu item for _all_ resources, but there are many different resource types
     13        that are unlikely (if ever) to be loaded via XHR/`fetch` (e.g. favicons, manifests, fonts,
     14        initial JS/CSS files, etc.) that it would likely add clutter and possibly confuse developers
     15        into thinking that URL Breakpoints can somehow pause things other than JS. Plus, this can
     16        always be changed in a followup, so better to do something minimal first.
     17
     18        * UserInterface/Controllers/DOMDebuggerManager.js:
     19        (WI.DOMDebuggerManager.prototype.urlBreakpointsMatchingURL): Added.
     20        Helper method to find all `WI.URLBreakpoint` that match a given URL, sorted by how exact
     21        they would match (e.g. a regex match is less exact than `===`).
     22
     23        * Localizations/en.lproj/localizedStrings.js:
     24
    1252022-01-13  Elliott Williams  <emw@apple.com>
    226
  • trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js

    r287409 r288029  
    116116localizedStrings["Add Cookie"] = "Add Cookie";
    117117localizedStrings["Add Header"] = "Add Header";
     118localizedStrings["Add JavaScript Breakpoint"] = "Add JavaScript Breakpoint";
    118119localizedStrings["Add New"] = "Add New";
    119120localizedStrings["Add New Class"] = "Add New Class";
     
    123124/* Text of button to add a new audit test case to the currently shown audit group. */
    124125localizedStrings["Add Test Case @ Audit Tab - Group"] = "Add Test Case";
     126localizedStrings["Add URL Breakpoint"] = "Add URL Breakpoint";
    125127localizedStrings["Add a Class"] = "Add a Class";
    126128localizedStrings["Add new breakpoint action after this action"] = "Add new breakpoint action after this action";
     
    362364localizedStrings["Condition"] = "Condition";
    363365localizedStrings["Conditional expression"] = "Conditional expression";
     366localizedStrings["Conic Gradient"] = "Conic Gradient";
    364367localizedStrings["Connecting"] = "Connecting";
    365368localizedStrings["Connection"] = "Connection";
     
    368371localizedStrings["Connection ID"] = "Connection ID";
    369372localizedStrings["Connection:"] = "Connection:";
    370 localizedStrings["Conic Gradient"] = "Conic Gradient";
    371373localizedStrings["Console"] = "Console";
    372374localizedStrings["Console Evaluation"] = "Console Evaluation";
     
    455457localizedStrings["Delete Descendant Breakpoints"] = "Delete Descendant Breakpoints";
    456458localizedStrings["Delete Inspector Bootstrap Script"] = "Delete Inspector Bootstrap Script";
     459localizedStrings["Delete JavaScript Breakpoint"] = "Delete JavaScript Breakpoint";
    457460localizedStrings["Delete Local Override"] = "Delete Local Override";
     461localizedStrings["Delete URL Breakpoint"] = "Delete URL Breakpoint";
     462localizedStrings["Delete URL Breakpoints"] = "Delete URL Breakpoints";
    458463localizedStrings["Delete Watch Expression"] = "Delete Watch Expression";
    459464localizedStrings["Delete probe"] = "Delete probe";
     
    11831188localizedStrings["Render Pipeline %d"] = "Render Pipeline %d";
    11841189localizedStrings["Rendering Frames"] = "Rendering Frames";
     1190localizedStrings["Repeating Conic Gradient"] = "Repeating Conic Gradient";
    11851191localizedStrings["Repeating Linear Gradient"] = "Repeating Linear Gradient";
    11861192localizedStrings["Repeating Radial Gradient"] = "Repeating Radial Gradient";
    1187 localizedStrings["Repeating Conic Gradient"] = "Repeating Conic Gradient";
    11881193localizedStrings["Request"] = "Request";
    11891194localizedStrings["Request & Response"] = "Request & Response";
     
    16041609/* Label for button to show CSS variables ungrouped */
    16051610localizedStrings["Ungrouped @ Computed Style variables grouping mode"] = "Ungrouped";
    1606 /* Section header for ungrouped CSS variables */
    1607 localizedStrings["Ungrouped @ Computed Style variables section"] = "Ungrouped";
    16081611/* Property value for `font-variant-capitals: unicase`. */
    16091612localizedStrings["Unicase @ Font Details Sidebar Property Value"] = "Unicase";
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/DOMDebuggerManager.js

    r268786 r288029  
    465465    }
    466466
     467    urlBreakpointsMatchingURL(url)
     468    {
     469        return this._urlBreakpoints
     470            .filter((urlBreakpoint) => {
     471                switch (urlBreakpoint.type) {
     472                case WI.URLBreakpoint.Type.Text:
     473                    return urlBreakpoint.url.toLowerCase() === url.toLowerCase();
     474
     475                case WI.URLBreakpoint.Type.RegularExpression:
     476                    return (new RegExp(urlBreakpoint.url, "i")).test(url);
     477                }
     478
     479                return false;
     480            })
     481            .sort((a, b) => {
     482                // Order URL breakpoints based on how closely they match the given URL.
     483                const typeRankings = [
     484                    WI.URLBreakpoint.Type.Text,
     485                    WI.URLBreakpoint.Type.RegularExpression,
     486                ];
     487                return typeRankings.indexOf(a.type) - typeRankings.indexOf(b.type);
     488            });
     489    }
     490
    467491    addURLBreakpoint(breakpoint)
    468492    {
  • trunk/Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js

    r276681 r288029  
    121121
    122122    if (location && (sourceCode instanceof WI.Script || (sourceCode instanceof WI.Resource && sourceCode.type === WI.Resource.Type.Script && !sourceCode.localResourceOverride))) {
    123         let existingBreakpoint = WI.debuggerManager.breakpointForSourceCodeLocation(location);
    124         if (existingBreakpoint) {
    125             contextMenu.appendItem(WI.UIString("Delete Breakpoint"), () => {
    126                 WI.debuggerManager.removeBreakpoint(existingBreakpoint);
     123        let existingJavaScriptBreakpoint = WI.debuggerManager.breakpointForSourceCodeLocation(location);
     124        if (existingJavaScriptBreakpoint) {
     125            contextMenu.appendItem(WI.UIString("Delete JavaScript Breakpoint"), () => {
     126                WI.debuggerManager.removeBreakpoint(existingJavaScriptBreakpoint);
    127127            });
    128128        } else {
    129             contextMenu.appendItem(WI.UIString("Add Breakpoint"), () => {
     129            contextMenu.appendItem(WI.UIString("Add JavaScript Breakpoint"), () => {
    130130                WI.debuggerManager.addBreakpoint(new WI.JavaScriptBreakpoint(location));
     131            });
     132        }
     133    }
     134
     135    if (sourceCode?.initiatorCallFrames) {
     136        let existingURLBreakpoints = WI.domDebuggerManager.urlBreakpointsMatchingURL(sourceCode.url);
     137        if (existingURLBreakpoints.length) {
     138            contextMenu.appendItem(existingURLBreakpoints.length === 1 ? WI.UIString("Delete URL Breakpoint") : WI.UIString("Delete URL Breakpoints"), () => {
     139                for (let urlBreakpoint of existingURLBreakpoints)
     140                    WI.domDebuggerManager.removeURLBreakpoint(urlBreakpoint);
     141            });
     142        } else {
     143            contextMenu.appendItem(WI.UIString("Add URL Breakpoint"), () => {
     144                WI.domDebuggerManager.addURLBreakpoint(new WI.URLBreakpoint(WI.URLBreakpoint.Type.Text, sourceCode.url));
    131145            });
    132146        }
Note: See TracChangeset for help on using the changeset viewer.