[GH-ISSUE #600] scripting no working #597

Closed
opened 2026-03-03 19:20:11 +03:00 by kerem · 13 comments
Owner

Originally created by @trycatchx on GitHub (Aug 28, 2020).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/600

Originally assigned to: @NghiaTranUIT on GitHub.

Proxyman version

Proxyman 2.5.1

macOS Version?

mac 10.15.5

I want to unzip my http Response
step1:
I use pako.js ,and put it into libs folder
step2:
i create Pako.js file put into addons folder, is to expose inflate function

// Pako.js
const pako = require('@libs/pako.js');

const inflate = (input) => {
    return pako.inflate(input);
};
exports.inflate = inflate;

step3:
open scripting and enter the following code :

// Addons List: https://docs.proxyman.io/scripting/addons
const { inflate } =  require("@addons/Pako.js");
function unzip( b64Data){
    var strData   = b64Data;
    // Convert binary string to character-number array
    var charData  = strData.split('').map(function(x){return x.charCodeAt(0);});
    // Turn number array into byte-array
    var binData   = new Uint8Array(charData);
    // // unzip
    var data    = inflate(binData);
    // Convert gunzipped byteArray back to ascii string:
    strData   = String.fromCharCode.apply(null, new Uint16Array(data));
    return decodeURIComponent(strData);
}


function onResponse(context, url, request, response) {

  console.log('begin');
   if(response.body != null) {
     var jsonString = JSON.stringify(response.body);
    console.log('2222'+unzip(jsonString));
  }
 
  // Done
  return response;
}

Console output:
begin
Error: incorrect header check
Error: Could not convert JSvalue to Dictionary. Please make sure the return value is a JS dictionary (Object)

can someone please tell me what went wrong ?

Originally created by @trycatchx on GitHub (Aug 28, 2020). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/600 Originally assigned to: @NghiaTranUIT on GitHub. ### Proxyman version Proxyman 2.5.1 ### macOS Version? mac 10.15.5 I want to unzip my http Response step1: I use [pako.js](https://raw.githubusercontent.com/nodeca/pako/master/dist/pako.js) ,and put it into `libs` folder step2: i create Pako.js file put into `addons` folder, is to expose `inflate` function ``` // Pako.js const pako = require('@libs/pako.js'); const inflate = (input) => { return pako.inflate(input); }; exports.inflate = inflate; ``` step3: open scripting and enter the following code : ``` // Addons List: https://docs.proxyman.io/scripting/addons const { inflate } = require("@addons/Pako.js"); function unzip( b64Data){ var strData = b64Data; // Convert binary string to character-number array var charData = strData.split('').map(function(x){return x.charCodeAt(0);}); // Turn number array into byte-array var binData = new Uint8Array(charData); // // unzip var data = inflate(binData); // Convert gunzipped byteArray back to ascii string: strData = String.fromCharCode.apply(null, new Uint16Array(data)); return decodeURIComponent(strData); } function onResponse(context, url, request, response) { console.log('begin'); if(response.body != null) { var jsonString = JSON.stringify(response.body); console.log('2222'+unzip(jsonString)); } // Done return response; } ``` Console output: begin ❌Error: incorrect header check ❌Error: Could not convert JSvalue to Dictionary. Please make sure the return value is a JS dictionary (Object) can someone please tell me what went wrong ?
kerem 2026-03-03 19:20:11 +03:00
  • closed this issue
  • added the
    Done
    label
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 28, 2020):

Let me investigate why it doesn't work in your case.

Btw, can you add this log on the onResponse func? I would like to see the Content-Type and what the value of body is @zhangchaojiong

console.log(response.headers)
console.log(response.body)
<!-- gh-comment-id:682432230 --> @NghiaTranUIT commented on GitHub (Aug 28, 2020): Let me investigate why it doesn't work in your case. Btw, can you add this log on the onResponse func? I would like to see the Content-Type and what the value of body is @zhangchaojiong ```javascript console.log(response.headers) console.log(response.body) ```
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 28, 2020):

Btw, It's better than I should provide a built-in addon for unzip/zip tasks.

<!-- gh-comment-id:682434041 --> @NghiaTranUIT commented on GitHub (Aug 28, 2020): Btw, It's better than I should provide a built-in addon for unzip/zip tasks.
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 28, 2020):

Thanks. Since your Content-Type is text/plain, so the response.body is a string, not JSON Object. Thus, you don't need to convert to JSON String (JSON.stringify).

<!-- gh-comment-id:682436873 --> @NghiaTranUIT commented on GitHub (Aug 28, 2020): Thanks. Since your Content-Type is text/plain, so the `response.body` is a string, not JSON Object. Thus, you don't need to convert to JSON String (JSON.stringify).
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 28, 2020):

Please try to remove this line and pass the response.body to the unzip() function

You can use check the type of typeof(response.body) to see what is the type before working on 👍

<!-- gh-comment-id:682437481 --> @NghiaTranUIT commented on GitHub (Aug 28, 2020): Please try to remove this line and pass the response.body to the unzip() function You can use check the type of `typeof(response.body)` to see what is the type before working on 👍
Author
Owner

@trycatchx commented on GitHub (Aug 28, 2020):

Thanks Reply @NghiaTranUIT
typeof(response.body) is string

i remove this line JSON.stringify

i alway get the same result :

begin
❌Error: incorrect header check 
❌Error: Could not convert JSvalue to Dictionary. Please make sure the return value is a JS dictionary (Object)

Then, I changed the code to this:

const { inflate } =  require("@addons/Pako.js");
function unzip( ){
  var b64Data   = 'H4sIAAAAAAAAAJ3UMQ7CMAwF0KugP2ewEzdpcxXUAbWAOiHUMqCqdyeVQAobfGXIYL8hP5ZXnEdkeNEk6vUgXTbLonC4zMjHFY/5Wm511ekdTsOCLKVp2rlIKOA2jTuBot/cr7BhobEwsbAloY8kDGyqoQ5H/oHsdwQ21cCmaspCz0L2jcYOgLHhNGw4TT1yVmBpuS9PZHWY35siqnxvimEvpE9FY4peQhfbhO0FDnuFqWAEAAA=';
    var strData   =b64Data ;
    // Convert binary string to character-number array
    var charData  = strData.split('').map(function(x){return x.charCodeAt(0);});
    // Turn number array into byte-array
    var binData   = new Uint8Array(charData);
    // // unzip
    var data    = inflate(binData);
    // Convert gunzipped byteArray back to ascii string:
    strData   = String.fromCharCode.apply(null, new Uint16Array(data));
    return decodeURIComponent(strData);
}


function onResponse(context, url, request, response) {

  console.log('begin');
  
   unzip();
  
 
  // Done
  return response;
}

Console output:

begin
❌Error: incorrect header check 
❌Error: Could not convert JSvalue to Dictionary. Please make sure the return value is a JS dictionary (Object)

I guess, is pako.js not successfully linked?

<!-- gh-comment-id:682443924 --> @trycatchx commented on GitHub (Aug 28, 2020): Thanks Reply @NghiaTranUIT typeof(response.body) is string i remove this line `JSON.stringify` i alway get the same result : ``` begin ❌Error: incorrect header check ❌Error: Could not convert JSvalue to Dictionary. Please make sure the return value is a JS dictionary (Object) ``` Then, I changed the code to this: ``` const { inflate } = require("@addons/Pako.js"); function unzip( ){ var b64Data = 'H4sIAAAAAAAAAJ3UMQ7CMAwF0KugP2ewEzdpcxXUAbWAOiHUMqCqdyeVQAobfGXIYL8hP5ZXnEdkeNEk6vUgXTbLonC4zMjHFY/5Wm511ekdTsOCLKVp2rlIKOA2jTuBot/cr7BhobEwsbAloY8kDGyqoQ5H/oHsdwQ21cCmaspCz0L2jcYOgLHhNGw4TT1yVmBpuS9PZHWY35siqnxvimEvpE9FY4peQhfbhO0FDnuFqWAEAAA='; var strData =b64Data ; // Convert binary string to character-number array var charData = strData.split('').map(function(x){return x.charCodeAt(0);}); // Turn number array into byte-array var binData = new Uint8Array(charData); // // unzip var data = inflate(binData); // Convert gunzipped byteArray back to ascii string: strData = String.fromCharCode.apply(null, new Uint16Array(data)); return decodeURIComponent(strData); } function onResponse(context, url, request, response) { console.log('begin'); unzip(); // Done return response; } ``` Console output: ``` begin ❌Error: incorrect header check ❌Error: Could not convert JSvalue to Dictionary. Please make sure the return value is a JS dictionary (Object) ``` I guess, is `pako.js` not successfully linked?
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 28, 2020):

Let me see 👍

<!-- gh-comment-id:682444590 --> @NghiaTranUIT commented on GitHub (Aug 28, 2020): Let me see 👍
Author
Owner

@trycatchx commented on GitHub (Aug 28, 2020):

@NghiaTranUIT I made it work

this is my code:

// Addons List: https://docs.proxyman.io/scripting/addons
const { inflate } =  require("@addons/Pako.js");

// Decode Baes64
const { base64Decode } = require("@addons/Base64Decode.js");



function unzip( ){
  var b64Data   = 'eNrLVMjJL0tVqMwvBQATqAO9';
    var strData   =  base64Decode(b64Data) ;
    // Convert binary string to character-number array
    var charData  = strData.split('').map(function(x){return x.charCodeAt(0);});
    // Turn number array into byte-array
    var binData   = new Uint8Array(charData);
    // // unzip
    var data    = inflate(binData, {"to":"string"});
    // Convert gunzipped byteArray back to ascii string:
    strData   = String.fromCharCode.apply(null, new Uint16Array(data));
    return decodeURIComponent(strData);
}


function onResponse(context, url, request, response) {

  console.log('begin');
  
  
     console.log('begin1'+ unzip());
 
  // Done
  return response;
}

Console output:

----------------------------------
19:43:20.257: [onResponse] with Request ID=8185
begin
begin1i love you
19:43:20.273 onResponse() is executed!
<!-- gh-comment-id:682480789 --> @trycatchx commented on GitHub (Aug 28, 2020): @NghiaTranUIT I made it work this is my code: ``` // Addons List: https://docs.proxyman.io/scripting/addons const { inflate } = require("@addons/Pako.js"); // Decode Baes64 const { base64Decode } = require("@addons/Base64Decode.js"); function unzip( ){ var b64Data = 'eNrLVMjJL0tVqMwvBQATqAO9'; var strData = base64Decode(b64Data) ; // Convert binary string to character-number array var charData = strData.split('').map(function(x){return x.charCodeAt(0);}); // Turn number array into byte-array var binData = new Uint8Array(charData); // // unzip var data = inflate(binData, {"to":"string"}); // Convert gunzipped byteArray back to ascii string: strData = String.fromCharCode.apply(null, new Uint16Array(data)); return decodeURIComponent(strData); } function onResponse(context, url, request, response) { console.log('begin'); console.log('begin1'+ unzip()); // Done return response; } ``` Console output: ``` ---------------------------------- 19:43:20.257: [onResponse] with Request ID=8185 begin begin1i love you 19:43:20.273 onResponse() is executed! ```
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 28, 2020):

Glad to hear that 😄

I'm not sure why var b64Data = "H4sIAAAAAAAAAwXB2w0AEBAEwFbWl2Y0IW4jQmziPNo3k6TuGK0Tj/ESVRs6yzkuHRnGIqPB92qzhg8yp62UMAAAAA=="; doesn't work. The same value is working on the web

<!-- gh-comment-id:682481676 --> @NghiaTranUIT commented on GitHub (Aug 28, 2020): Glad to hear that 😄 I'm not sure why `var b64Data = "H4sIAAAAAAAAAwXB2w0AEBAEwFbWl2Y0IW4jQmziPNo3k6TuGK0Tj/ESVRs6yzkuHRnGIqPB92qzhg8yp62UMAAAAA==";` doesn't work. The same value is working on the web
Author
Owner

@trycatchx commented on GitHub (Aug 28, 2020):

btw, Can you provide a built-in addon for unzip/zip tasks? Make work easier!

<!-- gh-comment-id:682481708 --> @trycatchx commented on GitHub (Aug 28, 2020): btw, Can you provide a built-in addon for unzip/zip tasks? Make work easier!
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 28, 2020):

Sure, I will open the ticket for it 👍

<!-- gh-comment-id:682481820 --> @NghiaTranUIT commented on GitHub (Aug 28, 2020): Sure, I will open the ticket for it 👍
Author
Owner

@trycatchx commented on GitHub (Aug 28, 2020):

@NghiaTranUIT thx!

<!-- gh-comment-id:682482047 --> @trycatchx commented on GitHub (Aug 28, 2020): @NghiaTranUIT thx!
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 29, 2020):

Good new @zhangchaojiong I discover why you weren't able to decode with your string

var b64Data   = 'H4sIAAAAAAAAAJ3UMQ7CMAwF0KugP2ewEzdpcxXUAbWAOiHUMqCqdyeVQAobfGXIYL8hP5ZXnEdkeNEk6vUgXTbLonC4zMjHFY/5Wm511ekdTsOCLKVp2rlIKOA2jTuBot/cr7BhobEwsbAloY8kDGyqoQ5H/oHsdwQ21cCmaspCz0L2jcYOgLHhNGw4TT1yVmBpuS9PZHWY35siqnxvimEvpE9FY4peQhfbhO0FDnuFqWAEAAA=';

It's because the atob/btoa funcs are different from base64Encode/base64Decode that Proxyman provides 😮

I fixed it and will send you an update today 👍

Work fine with your code

<!-- gh-comment-id:683232829 --> @NghiaTranUIT commented on GitHub (Aug 29, 2020): Good new @zhangchaojiong I discover why you weren't able to decode with your string ``` var b64Data = 'H4sIAAAAAAAAAJ3UMQ7CMAwF0KugP2ewEzdpcxXUAbWAOiHUMqCqdyeVQAobfGXIYL8hP5ZXnEdkeNEk6vUgXTbLonC4zMjHFY/5Wm511ekdTsOCLKVp2rlIKOA2jTuBot/cr7BhobEwsbAloY8kDGyqoQ5H/oHsdwQ21cCmaspCz0L2jcYOgLHhNGw4TT1yVmBpuS9PZHWY35siqnxvimEvpE9FY4peQhfbhO0FDnuFqWAEAAA='; ``` It's because the atob/btoa funcs are different from base64Encode/base64Decode that Proxyman provides 😮 I fixed it and will send you an update today 👍 Work fine with your code
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 29, 2020):

@zhangchaojiong let check out this build: https://download.proxyman.io/beta/Proxyman_2.5.1_Add_atob_btoa.Add_Pako.dmg

const { inflate } =  require("@addons/Pako.js");
function unzip( ){
  var b64Data   = 'H4sIAAAAAAAAAJ3UMQ7CMAwF0KugP2ewEzdpcxXUAbWAOiHUMqCqdyeVQAobfGXIYL8hP5ZXnEdkeNEk6vUgXTbLonC4zMjHFY/5Wm511ekdTsOCLKVp2rlIKOA2jTuBot/cr7BhobEwsbAloY8kDGyqoQ5H/oHsdwQ21cCmaspCz0L2jcYOgLHhNGw4TT1yVmBpuS9PZHWY35siqnxvimEvpE9FY4peQhfbhO0FDnuFqWAEAAA=';
  return inflate(b64Data);
}

function onResponse(context, url, request, response) {
  // console.log(response);

  var jsonString = unzip();
  var json = JSON.parse(jsonString);
  console.log(json)

  // Done
  return response;
}
Screen Shot 2020-08-29 at 11 26 32

notes

  • Please delete your Pako file in addon folder. Proxyman will override with the correct one
  • If you need to use atob/btoa, please use it from Base64.js
<!-- gh-comment-id:683234571 --> @NghiaTranUIT commented on GitHub (Aug 29, 2020): @zhangchaojiong let check out this build: https://download.proxyman.io/beta/Proxyman_2.5.1_Add_atob_btoa.Add_Pako.dmg ``` const { inflate } = require("@addons/Pako.js"); function unzip( ){ var b64Data = 'H4sIAAAAAAAAAJ3UMQ7CMAwF0KugP2ewEzdpcxXUAbWAOiHUMqCqdyeVQAobfGXIYL8hP5ZXnEdkeNEk6vUgXTbLonC4zMjHFY/5Wm511ekdTsOCLKVp2rlIKOA2jTuBot/cr7BhobEwsbAloY8kDGyqoQ5H/oHsdwQ21cCmaspCz0L2jcYOgLHhNGw4TT1yVmBpuS9PZHWY35siqnxvimEvpE9FY4peQhfbhO0FDnuFqWAEAAA='; return inflate(b64Data); } function onResponse(context, url, request, response) { // console.log(response); var jsonString = unzip(); var json = JSON.parse(jsonString); console.log(json) // Done return response; } ``` <img width="1521" alt="Screen Shot 2020-08-29 at 11 26 32" src="https://user-images.githubusercontent.com/5878421/91628506-828b2e80-e9ea-11ea-8d03-ae90e3f1e8e4.png"> ### notes - Please delete your Pako file in addon folder. Proxyman will override with the correct one - If you need to use atob/btoa, please use it from Base64.js
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Proxyman#597
No description provided.