Skip to content

Commit 01b8e35

Browse files
committed
Release version 2
Changes: * Added Postman v9.x.x support * Simplified usage [pass one argument to postman folder instead of requester.js or app.asar] * Simplified patching process * Added -v flag to enable verbose output * Updated dependencies
1 parent dc36256 commit 01b8e35

File tree

7 files changed

+936
-178
lines changed

7 files changed

+936
-178
lines changed

.github/workflows/postman.yml

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
inputs:
1010
version:
1111
default: "latest"
12-
description: "Postman Version, accepted values: ['latest', 'version/8.x.x']"
12+
description: "Postman Version, accepted values: ['latest', 'version/8.x.x', 'version/9.x.x']"
1313
required: true
1414

1515

@@ -43,7 +43,7 @@ jobs:
4343

4444
- uses: actions/setup-node@v2
4545
with:
46-
node-version: '14'
46+
node-version: '16'
4747

4848
- name : "Install aria2 downloader"
4949
run: sudo apt update && sudo apt install aria2
@@ -70,33 +70,24 @@ jobs:
7070
echo "VERSION=${version}" >> $GITHUB_ENV
7171
rm -v ${file}
7272
73-
- name : "Find requester.js/app.asar file"
73+
- name : "Check if app.asar file is found"
7474
run: |
75-
path=$(grep -R --text 'getWorkingInScratchpadBanner' $PWD/Postman* | cut -d':' -f1 | uniq | egrep 'requester|app.asar')
75+
path=$(grep -R --text 'getWorkingInScratchpadBanner' $PWD/Postman* | cut -d':' -f1 | uniq | grep 'app.asar')
7676
77-
if [[ "${path}" == *requester.js ]]; then
78-
echo "requester.js path: ${path}"
79-
echo "REQUESTER_JS=${path}" >> $GITHUB_ENV
80-
else
77+
if [[ "${path}" == *app.asar ]]; then
8178
echo "app.asar path: ${path}"
82-
echo "APP_ASAR=${path}" >> $GITHUB_ENV
79+
else
80+
echo "No app.asar file"
81+
echo "NO_APP_ASAR=True" >> $GITHUB_ENV
8382
fi
8483
85-
86-
- name : "Fix Scratch Pad Banner [requester.js]"
87-
if: ${{ env.REQUESTER_JS }}
84+
- name : "Fix Scratch Pad Banner"
8885
run: |
8986
npm install
90-
node fix.js -r ${{ env.REQUESTER_JS }}
91-
92-
- name : "Fix Scratch Pad Banner [app.asar]"
93-
if: ${{ env.APP_ASAR }}
94-
run: |
95-
npm install
96-
node fix.js -a ${{ env.APP_ASAR }}
97-
98-
- name : "Postman Cleanup [requester.js]"
99-
if: ${{ env.REQUESTER_JS }}
87+
node fix.js -p ./Postman* -v
88+
89+
- name : "Postman Cleanup"
90+
if: ${{ env.NO_APP_ASAR }}
10091
continue-on-error: true
10192
run: |
10293
curl -sf 'https://gobinaries.com/tj/node-prune' | sudo sh
@@ -109,11 +100,11 @@ jobs:
109100
110101
- name : "Calculate Checksum"
111102
run: |
112-
echo -e "\nChecksum - ${{ matrix.os_name }}\n" >> checksum
113-
echo -n "SHA1: " >> checksum
114-
sha1sum Postman*.tar.xz >> checksum
115-
echo -n "SHA256: " >> checksum
116-
sha256sum Postman*.tar.xz >> checksum
103+
echo -e "\nChecksum - ${{ matrix.os_name }}\n" | tee -a checksum
104+
echo -n "SHA1: " | tee -a checksum
105+
sha1sum Postman*.tar.xz | tee -a checksum
106+
echo -n "SHA256: " | tee -a checksum
107+
sha256sum Postman*.tar.xz | tee -a checksum
117108
118109
- name: Release Files
119110
uses: softprops/action-gh-release@v1

README.md

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Postman Scratchpad Banner Fix
2-
### Remove Scratchpad Banner from Postman 8.x.x
2+
### Remove Scratchpad Banner from Postman 8.x.x and 9.x.x
33

44
# Description
55
Starting from [Postman](https://www.postman.com/) v8, working locally in scratchpad mode introduces this annoying banner which can't be disabled completely.
@@ -8,69 +8,32 @@ Starting from [Postman](https://www.postman.com/) v8, working locally in scratch
88

99
Therefore, I've created this repo to solve the problem, I've patched postman files to disable the scratchpad banner
1010

11-
Tested on Postman versions from *`8.1.0`* to *`8.10.0`*
11+
Tested on Postman versions from *`8.1.0`* to *`9.3.1`*
1212

1313
# Install
1414
* Install [node.js](https://nodejs.org/en/download/)
1515
* Clone this repo `git clone https://github.com/3omar-mostafa/Postman-Scratchpad-Banner-Fix.git`
1616
* `cd Postman-Scratchpad-Banner-Fix`
1717
* Run ***`npm install`*** to install dependencies
1818

19-
# Linux
2019
# Usage
2120
## Patch your already installed postman
22-
Run ***`node fix.js -r ${requester_js}`*** , where ***`${requester_js}`*** is Postman file (***`requester.js`***) which renders scratchpad banner
23-
24-
### requester.js path:
25-
It can be found on path like this: ***`${Postman_install_dir}/resources/app/js/requester.js`***
21+
Run ***`node fix.js -p ${postman_dir}`*** , where ***`${postman_dir}`*** is Postman installation directory
2622

2723
## Download patched postman
28-
You can find downloads for linux and macos at [Releases](https://github.com/3omar-mostafa/Postman-Scratchpad-Banner-Fix/releases)
29-
30-
# MacOS
31-
# Usage
32-
## Patch your already installed postman
33-
34-
* For Postman version `8.0.0` to `8.10.0`
35-
* Run ***`node fix.js -r ${requester_js}`*** , where ***`${requester_js}`*** is Postman file (***`requester.js`***) which renders scratchpad banner
36-
* ***`${requester_js}`*** can be found on path like this: ***`${Postman_install_dir}/Contents/Resources/app/js/requester.js`***
37-
38-
* For Postman version `8.11.0` or above
39-
* Run ***`node fix.js -a ${app_asar}`*** , where ***`${app_asar}`*** is Postman file (***`app.asar`***) which is like a `tar` archive and contains most of postman's files
40-
* ***`${app_asar}`*** can be found on path like this: ***`${Postman_install_dir}/Contents/Resources/app.asar`***
41-
* You can learn more about *`asar`* file format [from here](https://github.com/electron/asar).
42-
43-
## Download patched postman
44-
You can find downloads for linux and macos at [Releases](https://github.com/3omar-mostafa/Postman-Scratchpad-Banner-Fix/releases)
45-
46-
# Windows
47-
# Usage
48-
## Patch your already installed postman
49-
Run ***`node fix.js -a ${app_asar}`*** , where ***`${app_asar}`*** is Postman file (***`app.asar`***) which is like a `tar` archive and contains most of postman's files
50-
51-
### app.asar path:
52-
It can be found on path like this: ***`%localappdata%\Postman\app-8.10.0\resources\app.asar`***
53-
54-
You can learn more about *`asar`* file format [from here](https://github.com/electron/asar).
55-
56-
## Download patched postman
57-
Windows is not included because its installer is *`exe`* file which I can extract and patch the files, but unfortunately I can not re-create the same installer, but you can still patch you existing installation
24+
* You can find downloads for Linux and MacOS at [Releases](https://github.com/3omar-mostafa/Postman-Scratchpad-Banner-Fix/releases)
25+
* Windows is not included because its installer is *`exe`* file which I can extract and patch the files, but unfortunately I can not re-create the same installer, but you can still patch you existing installation
5826

5927
# Methodology and Manual Patching
60-
The file which is responsible for displaying scratchpad banner is ***`requester.js`***
28+
* There are some files which are responsible for displaying scratchpad banner as ***`requester.js`*** and ***`scratchpad.js`*** in newer versions
29+
* These files contains ***`getWorkingInScratchpadBanner`*** , ***`getScratchpadBannerMode`*** functions and ***`SHOW_BANNER_IN_SCRATCHPAD`*** flag
6130

62-
I've made three changes to the file (they are redundant and any one of them is enough, but made three for more reliability)
31+
I've made changes to these files
6332

6433
* ***`getWorkingInScratchpadBanner`***
6534
* Modified this function to automatically close the scratchpad banner instead of creating it, using ***`this.closeBanner()`*** function call
6635

67-
* ***`SHOW_BANNER_IN_SCRATCHPAD`***
68-
* Modified this constant to equal ***`HIDE_SCRATCHPAD_BANNER`*** instead
69-
70-
* ***`_constants_ScratchpadConstants__WEBPACK_IMPORTED_MODULE_8__["SHOW_BANNER_IN_SCRATCHPAD"]`***
71-
* Modified this object to return ***`HIDE_SCRATCHPAD_BANNER`*** instead
72-
73-
If you are on windows/macos, you can use [asar](https://github.com/electron/asar#command-line-utility) to extract ***`app.asar`*** and modify ***`requester.js`*** then repack it again
36+
If you are on windows/macos, you may find no code in Postman installation directory, instead you may find ***`app.asar`*** file (which is like a tar archive file) and you can use [asar](https://github.com/electron/asar#command-line-utility) to extract ***`app.asar`*** and modify the files then repack it again
7437

7538
# Notes
7639
This repo use github actions to automate checking for new releases every month, also can run manually for custom version

fix.js

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,28 @@ let os = require('os')
66
let esprima = require('esprima');
77
let colors = require('chalk'); // print colored text into console
88
let asar = require('asar');
9+
let replace = require("replace");
910
let { args } = require('./parse_args');
1011
let { findNestedObject, replaceRangeInString, printDebug } = require("./utils");
1112

13+
/**
14+
* Get Relevant Files to process, these files are javascript files containing `getWorkingInScratchpadBanner` function,
15+
* or asar archives
16+
* @param postmanDirectory Postman Directory to search in
17+
* @returns Array of strings containing found file paths
18+
*/
19+
function getRelevantFilePaths(postmanDirectory) {
20+
let searchResults = replace({
21+
regex: "getWorkingInScratchpadBanner",
22+
include: "*.js,app.asar",
23+
exclude: "*CommonLazyChunk.js", // This file causes parsing errors and has no effect on showing/hiding scratchpad
24+
paths: [postmanDirectory],
25+
recursive: true,
26+
silent: true,
27+
});
28+
return searchResults.map(obj => obj.path);
29+
}
30+
1231

1332
function injectCode(rawFileData, searchQuery, replaceString) {
1433
// We need to reparse the data after each manipulation because we have changed their position
@@ -23,6 +42,8 @@ function injectCode(rawFileData, searchQuery, replaceString) {
2342

2443

2544
async function fixPostmanScratchpadBanner(requester_js_path) {
45+
console.log(colors.yellow(`[INFO] Processing ${requester_js_path}`));
46+
try {
2647

2748
let data = String(await fs.readFileSync(requester_js_path));
2849

@@ -36,48 +57,45 @@ async function fixPostmanScratchpadBanner(requester_js_path) {
3657

3758
data = injectCode(data, getWorkingInScratchpadBanner.query, getWorkingInScratchpadBanner.replaceString);
3859

39-
let RETURN_SHOW_BANNER_IN_SCRATCHPAD = {
40-
query: {
41-
type: 'ReturnStatement',
42-
argument: { type: 'Identifier', name: 'SHOW_BANNER_IN_SCRATCHPAD' }
43-
},
44-
replaceString: "return HIDE_SCRATCHPAD_BANNER;"
45-
};
46-
47-
data = injectCode(data, RETURN_SHOW_BANNER_IN_SCRATCHPAD.query, RETURN_SHOW_BANNER_IN_SCRATCHPAD.replaceString);
48-
49-
let CONST_SHOW_BANNER_IN_SCRATCHPAD = {
50-
query: {
51-
type: 'VariableDeclarator',
52-
id: { type: 'Identifier', name: 'SHOW_BANNER_IN_SCRATCHPAD' }
53-
},
54-
replaceString: "SHOW_BANNER_IN_SCRATCHPAD = HIDE_SCRATCHPAD_BANNER;"
55-
};
56-
57-
data = injectCode(data, CONST_SHOW_BANNER_IN_SCRATCHPAD.query, CONST_SHOW_BANNER_IN_SCRATCHPAD.replaceString);
58-
59-
console.log(colors.yellow(`[INFO] Saving the file into ${requester_js_path}`))
60+
console.log(colors.yellow(`[INFO] Saving the file into ${requester_js_path}`));
6061
await fs.writeFileSync(requester_js_path, data);
6162

63+
} catch (e) {
64+
if (args.verbose) {
65+
console.log(colors.red(`------------------------------------------------`));
66+
console.log(colors.red(`[ERROR] Error Processing ${requester_js_path}`));
67+
console.log(colors.red(`[ERROR] ${e.stack}`));
68+
console.log(colors.red(`------------------------------------------------`));
69+
}
70+
}
71+
72+
console.log(colors.yellow(`------------------------------------------------`));
6273
}
6374

75+
76+
// Main function
6477
(async function () {
6578

66-
if (args.app_asar) {
67-
let tmpDir = path.join(os.tmpdir(), "postman_app.asar_extracted");
68-
asar.extractAll(args.app_asar, tmpDir);
69-
console.log(colors.yellow(`[INFO] Extracted ${args.app_asar} into ${tmpDir}`));
70-
let requester_js = path.join(tmpDir, 'js', 'requester.js');
79+
let postmanDirectory = args.postman_dir;
7180

72-
await fixPostmanScratchpadBanner(requester_js);
81+
for (let filepath of getRelevantFilePaths(postmanDirectory)) {
82+
if (filepath.toLowerCase().endsWith("app.asar")) {
83+
let app_asar = filepath;
84+
let tmpDir = path.join(os.tmpdir(), "postman_app.asar_extracted");
85+
asar.extractAll(app_asar, tmpDir);
86+
console.log(colors.yellow(`[INFO] Extracted ${app_asar} into ${tmpDir}`));
7387

74-
await asar.createPackage(tmpDir, args.app_asar);
75-
console.log(colors.yellow(`[INFO] Archived ${tmpDir} back into ${args.app_asar}`));
76-
await fs.rmSync(tmpDir, { recursive: true });
88+
for (let filepath of getRelevantFilePaths(tmpDir)) {
89+
await fixPostmanScratchpadBanner(filepath);
90+
}
7791

78-
} else {
79-
await fixPostmanScratchpadBanner(args.requester_js);
80-
}
92+
await asar.createPackage(tmpDir, app_asar);
93+
console.log(colors.yellow(`[INFO] Archived ${tmpDir} back into ${app_asar}`));
94+
await fs.rmSync(tmpDir, { recursive: true });
8195

96+
} else {
97+
await fixPostmanScratchpadBanner(filepath);
98+
}
99+
}
82100
}
83101
)()

0 commit comments

Comments
 (0)