arn-browser 0.1.46 → 0.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arn-browser",
3
- "version": "0.1.46",
3
+ "version": "0.1.48",
4
4
  "description": "A lightweight, browser autmation helper.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -221,7 +221,7 @@ function sanitizeResponseHeaders(headers, logger, url) {
221
221
  * @param {boolean} stripLogger - Whether to log stripped headers
222
222
  * @returns {Promise<Object>} - The response object containing status, headers, and body
223
223
  */
224
- async function fetchWithClient(useCache, url, requestHeaders, method, useFullUrl, logger, proxyAgent, stripHeaders, stripLogger) {
224
+ async function fetchWithClient(useCache, url, requestHeaders, method, useFullUrl, logger, proxyAgent, stripHeaders, stripLogger, postData) {
225
225
  // Determine the cache key based on configuration
226
226
  let mainUrl = new URL(url).origin + new URL(url).pathname;
227
227
  if (useFullUrl) {
@@ -252,6 +252,26 @@ async function fetchWithClient(useCache, url, requestHeaders, method, useFullUrl
252
252
  request = request.agent(proxyAgent);
253
253
  }
254
254
 
255
+ // Forward POST/PUT/PATCH request body if present
256
+ if (postData && (method !== "GET" && method !== "HEAD")) {
257
+ let bodyToSend = postData;
258
+ if (typeof postData !== "string") {
259
+ const contentTypeKey = Object.keys(finalHeaders).find(k => k.toLowerCase() === "content-type");
260
+ const contentType = contentTypeKey ? String(finalHeaders[contentTypeKey]).toLowerCase() : "";
261
+ if (
262
+ contentType.includes("json") ||
263
+ contentType.includes("urlencoded") ||
264
+ contentType.includes("xml") ||
265
+ contentType.includes("text/")
266
+ ) {
267
+ bodyToSend = Buffer.isBuffer(postData)
268
+ ? postData.toString("utf-8")
269
+ : Buffer.from(postData).toString("utf-8");
270
+ }
271
+ }
272
+ request = request.send(bodyToSend);
273
+ }
274
+
255
275
  const response = await request;
256
276
 
257
277
  // Determine the correct body type (Buffer for binary, text for others)
@@ -489,6 +509,7 @@ export async function pwRoute(options = {}) {
489
509
  ? currentConfig.xhrProxyAgent
490
510
  : currentConfig.proxyAgent;
491
511
 
512
+ const postData = request.postDataBuffer ? request.postDataBuffer() : request.postData();
492
513
  const response = await fetchWithClient(
493
514
  currentConfig.useCache,
494
515
  url,
@@ -497,8 +518,9 @@ export async function pwRoute(options = {}) {
497
518
  currentConfig.useFullUrl,
498
519
  currentConfig.logger,
499
520
  agentToUse,
500
- currentConfig.stripGotHeaders,
501
- currentConfig.stripGotLogger
521
+ isXhrOrFetch ? false : currentConfig.stripGotHeaders,
522
+ currentConfig.stripGotLogger,
523
+ postData
502
524
  );
503
525
 
504
526
  if (response) {
@@ -224,7 +224,7 @@ function sanitizeResponseHeaders(headers, logger, url) {
224
224
  * @param {boolean} stripLogger - Whether to log stripped headers
225
225
  * @returns {Promise<Object>} - The response object containing status, headers, and body
226
226
  */
227
- async function fetchWithClient(useCache, url, requestHeaders, method, useFullUrl, logger, proxyAgent, stripHeaders, stripLogger) {
227
+ async function fetchWithClient(useCache, url, requestHeaders, method, useFullUrl, logger, proxyAgent, stripHeaders, stripLogger, postData) {
228
228
  // Determine the cache key based on configuration
229
229
  let mainUrl = new URL(url).origin + new URL(url).pathname;
230
230
  if (useFullUrl) {
@@ -255,6 +255,26 @@ async function fetchWithClient(useCache, url, requestHeaders, method, useFullUrl
255
255
  request = request.agent(proxyAgent);
256
256
  }
257
257
 
258
+ // Forward POST/PUT/PATCH request body if present
259
+ if (postData && (method !== "GET" && method !== "HEAD")) {
260
+ let bodyToSend = postData;
261
+ if (typeof postData !== "string") {
262
+ const contentTypeKey = Object.keys(finalHeaders).find(k => k.toLowerCase() === "content-type");
263
+ const contentType = contentTypeKey ? String(finalHeaders[contentTypeKey]).toLowerCase() : "";
264
+ if (
265
+ contentType.includes("json") ||
266
+ contentType.includes("urlencoded") ||
267
+ contentType.includes("xml") ||
268
+ contentType.includes("text/")
269
+ ) {
270
+ bodyToSend = Buffer.isBuffer(postData)
271
+ ? postData.toString("utf-8")
272
+ : Buffer.from(postData).toString("utf-8");
273
+ }
274
+ }
275
+ request = request.send(bodyToSend);
276
+ }
277
+
258
278
  const response = await request;
259
279
 
260
280
  // Determine the correct body type (Buffer for binary, text for others)
@@ -504,8 +524,9 @@ export async function ppRoute(options = {}) {
504
524
  currentConfig.useFullUrl,
505
525
  currentConfig.logger,
506
526
  agentToUse,
507
- currentConfig.stripGotHeaders,
508
- currentConfig.stripGotLogger
527
+ isXhrOrFetch ? false : currentConfig.stripGotHeaders,
528
+ currentConfig.stripGotLogger,
529
+ request.postData()
509
530
  );
510
531
 
511
532
  if (response) {