How to use disposeAPIResponse method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

networkDispatchers.js

Source: networkDispatchers.js Github

copy
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.WebSocketDispatcher = exports.RouteDispatcher = exports.ResponseDispatcher = exports.RequestDispatcher = exports.APIRequestContextDispatcher = void 0;
7
8var _fetch = require("../server/fetch");
9
10var _network = require("../server/network");
11
12var _dispatcher = require("./dispatcher");
13
14var _frameDispatcher = require("./frameDispatcher");
15
16/**
17 * Copyright (c) Microsoft Corporation.
18 *
19 * Licensed under the Apache License, Version 2.0 (the 'License");
20 * you may not use this file except in compliance with the License.
21 * You may obtain a copy of the License at
22 *
23 * http://www.apache.org/licenses/LICENSE-2.0
24 *
25 * Unless required by applicable law or agreed to in writing, software
26 * distributed under the License is distributed on an "AS IS" BASIS,
27 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 * See the License for the specific language governing permissions and
29 * limitations under the License.
30 */
31class RequestDispatcher extends _dispatcher.Dispatcher {
32  static from(scope, request) {
33    const result = (0, _dispatcher.existingDispatcher)(request);
34    return result || new RequestDispatcher(scope, request);
35  }
36
37  static fromNullable(scope, request) {
38    return request ? RequestDispatcher.from(scope, request) : undefined;
39  }
40
41  constructor(scope, request) {
42    const postData = request.postDataBuffer();
43    super(scope, request, 'Request', {
44      frame: _frameDispatcher.FrameDispatcher.from(scope, request.frame()),
45      url: request.url(),
46      resourceType: request.resourceType(),
47      method: request.method(),
48      postData: postData === null ? undefined : postData.toString('base64'),
49      headers: request.headers(),
50      isNavigationRequest: request.isNavigationRequest(),
51      redirectedFrom: RequestDispatcher.fromNullable(scope, request.redirectedFrom())
52    });
53    this._type_Request = void 0;
54    this._type_Request = true;
55  }
56
57  async rawRequestHeaders(params) {
58    return {
59      headers: await this._object.rawRequestHeaders()
60    };
61  }
62
63  async response() {
64    return {
65      response: (0, _dispatcher.lookupNullableDispatcher)(await this._object.response())
66    };
67  }
68
69}
70
71exports.RequestDispatcher = RequestDispatcher;
72
73class ResponseDispatcher extends _dispatcher.Dispatcher {
74  static from(scope, response) {
75    const result = (0, _dispatcher.existingDispatcher)(response);
76    return result || new ResponseDispatcher(scope, response);
77  }
78
79  static fromNullable(scope, response) {
80    return response ? ResponseDispatcher.from(scope, response) : undefined;
81  }
82
83  constructor(scope, response) {
84    super(scope, response, 'Response', {
85      // TODO: responses in popups can point to non-reported requests.
86      request: RequestDispatcher.from(scope, response.request()),
87      url: response.url(),
88      status: response.status(),
89      statusText: response.statusText(),
90      headers: response.headers(),
91      timing: response.timing()
92    });
93    this._type_Response = true;
94  }
95
96  async body() {
97    return {
98      binary: (await this._object.body()).toString('base64')
99    };
100  }
101
102  async securityDetails() {
103    return {
104      value: (await this._object.securityDetails()) || undefined
105    };
106  }
107
108  async serverAddr() {
109    return {
110      value: (await this._object.serverAddr()) || undefined
111    };
112  }
113
114  async rawResponseHeaders(params) {
115    return {
116      headers: await this._object.rawResponseHeaders()
117    };
118  }
119
120  async sizes(params) {
121    return {
122      sizes: await this._object.sizes()
123    };
124  }
125
126}
127
128exports.ResponseDispatcher = ResponseDispatcher;
129
130class RouteDispatcher extends _dispatcher.Dispatcher {
131  static from(scope, route) {
132    const result = (0, _dispatcher.existingDispatcher)(route);
133    return result || new RouteDispatcher(scope, route);
134  }
135
136  constructor(scope, route) {
137    super(scope, route, 'Route', {
138      // Context route can point to a non-reported request.
139      request: RequestDispatcher.from(scope, route.request())
140    });
141    this._type_Route = true;
142  }
143
144  async continue(params, metadata) {
145    await this._object.continue({
146      url: params.url,
147      method: params.method,
148      headers: params.headers,
149      postData: params.postData ? Buffer.from(params.postData, 'base64') : undefined
150    });
151  }
152
153  async fulfill(params) {
154    await this._object.fulfill(params);
155  }
156
157  async abort(params) {
158    await this._object.abort(params.errorCode || 'failed');
159  }
160
161}
162
163exports.RouteDispatcher = RouteDispatcher;
164
165class WebSocketDispatcher extends _dispatcher.Dispatcher {
166  constructor(scope, webSocket) {
167    super(scope, webSocket, 'WebSocket', {
168      url: webSocket.url()
169    });
170    this._type_EventTarget = true;
171    this._type_WebSocket = true;
172    webSocket.on(_network.WebSocket.Events.FrameSent, event => this._dispatchEvent('frameSent', event));
173    webSocket.on(_network.WebSocket.Events.FrameReceived, event => this._dispatchEvent('frameReceived', event));
174    webSocket.on(_network.WebSocket.Events.SocketError, error => this._dispatchEvent('socketError', {
175      error
176    }));
177    webSocket.on(_network.WebSocket.Events.Close, () => this._dispatchEvent('close', {}));
178  }
179
180}
181
182exports.WebSocketDispatcher = WebSocketDispatcher;
183
184class APIRequestContextDispatcher extends _dispatcher.Dispatcher {
185  static from(scope, request) {
186    const result = (0, _dispatcher.existingDispatcher)(request);
187    return result || new APIRequestContextDispatcher(scope, request);
188  }
189
190  static fromNullable(scope, request) {
191    return request ? APIRequestContextDispatcher.from(scope, request) : undefined;
192  }
193
194  constructor(scope, request) {
195    super(scope, request, 'APIRequestContext', {}, true);
196    this._type_APIRequestContext = true;
197    request.once(_fetch.APIRequestContext.Events.Dispose, () => {
198      if (!this._disposed) super._dispose();
199    });
200  }
201
202  async storageState(params) {
203    return this._object.storageState();
204  }
205
206  async dispose(params) {
207    this._object.dispose();
208  }
209
210  async fetch(params, metadata) {
211    const fetchResponse = await this._object.fetch(params, metadata);
212    return {
213      response: {
214        url: fetchResponse.url,
215        status: fetchResponse.status,
216        statusText: fetchResponse.statusText,
217        headers: fetchResponse.headers,
218        fetchUid: fetchResponse.fetchUid
219      }
220    };
221  }
222
223  async fetchResponseBody(params, metadata) {
224    const buffer = this._object.fetchResponses.get(params.fetchUid);
225
226    return {
227      binary: buffer ? buffer.toString('base64') : undefined
228    };
229  }
230
231  async fetchLog(params, metadata) {
232    const log = this._object.fetchLog.get(params.fetchUid) || [];
233    return {
234      log
235    };
236  }
237
238  async disposeAPIResponse(params, metadata) {
239    this._object.disposeResponse(params.fetchUid);
240  }
241
242}
243
244exports.APIRequestContextDispatcher = APIRequestContextDispatcher;
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)