@@ -49,9 +49,13 @@ import requestPayloadTreeStyles from './requestPayloadTree.css.js';
4949import requestPayloadViewStyles from './requestPayloadView.css.js' ;
5050const UIStrings = {
5151 /**
52- *@description A context menu item in the Watch Expressions Sidebar Pane of the Sources panel and Network pane request .
52+ *@description A context menu item Payload View of the Network panel to copy a parsed value .
5353 */
5454 copyValue : 'Copy value' ,
55+ /**
56+ *@description A context menu item Payload View of the Network panel to copy the payload.
57+ */
58+ copyPayload : 'Copy' ,
5559 /**
5660 * @description Text in Request Payload View of the Network panel. This is a noun-phrase meaning the
5761 * payload of a network request.
@@ -160,17 +164,16 @@ export class RequestPayloadView extends UI.Widget.VBox {
160164 this . request . removeEventListener ( SDK . NetworkRequest . Events . REQUEST_HEADERS_CHANGED , this . refreshFormData , this ) ;
161165 }
162166
163- private addEntryContextMenuHandler ( treeElement : UI . TreeOutline . TreeElement , value : string ) : void {
167+ private addEntryContextMenuHandler (
168+ treeElement : UI . TreeOutline . TreeElement , menuItem : string , jslogContext : string , getValue : ( ) => string ) : void {
164169 treeElement . listItemElement . addEventListener ( 'contextmenu' , event => {
165170 event . consume ( true ) ;
166171 const contextMenu = new UI . ContextMenu . ContextMenu ( event ) ;
167- const decodedValue = decodeURIComponent ( value ) ;
168- const copyDecodedValueHandler = ( ) : void => {
172+ const copyValueHandler = ( ) : void => {
169173 Host . userMetrics . actionTaken ( Host . UserMetrics . Action . NetworkPanelCopyValue ) ;
170- Host . InspectorFrontendHost . InspectorFrontendHostInstance . copyText ( decodedValue ) ;
174+ Host . InspectorFrontendHost . InspectorFrontendHostInstance . copyText ( getValue ( ) ) ;
171175 } ;
172- contextMenu . clipboardSection ( ) . appendItem (
173- i18nString ( UIStrings . copyValue ) , copyDecodedValueHandler , { jslogContext : 'copy-value' } ) ;
176+ contextMenu . clipboardSection ( ) . appendItem ( menuItem , copyValueHandler , { jslogContext} ) ;
174177 void contextMenu . show ( ) ;
175178 } ) ;
176179 }
@@ -249,8 +252,10 @@ export class RequestPayloadView extends UI.Widget.VBox {
249252 sourceTextElement . textContent = trim ? text . substr ( 0 , MAX_LENGTH ) : text ;
250253
251254 const sourceTreeElement = new UI . TreeOutline . TreeElement ( sourceTextElement ) ;
255+
252256 treeElement . removeChildren ( ) ;
253257 treeElement . appendChild ( sourceTreeElement ) ;
258+ this . addEntryContextMenuHandler ( sourceTreeElement , i18nString ( UIStrings . copyPayload ) , 'copy-payload' , ( ) => text ) ;
254259 if ( ! trim ) {
255260 return ;
256261 }
@@ -350,7 +355,8 @@ export class RequestPayloadView extends UI.Widget.VBox {
350355 }
351356
352357 const paramTreeElement = new UI . TreeOutline . TreeElement ( paramNameValue ) ;
353- this . addEntryContextMenuHandler ( paramTreeElement , param . value ) ;
358+ this . addEntryContextMenuHandler (
359+ paramTreeElement , i18nString ( UIStrings . copyValue ) , 'copy-value' , ( ) => decodeURIComponent ( param . value ) ) ;
354360 paramsTreeElement . appendChild ( paramTreeElement ) ;
355361 }
356362
0 commit comments