@open-wa/wa-automate 4.52.0 → 4.52.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,7 +51,7 @@ const tools_1 = require("../utils/tools");
51
51
  const script_preloader_1 = require("./script_preloader");
52
52
  const patch_manager_1 = require("./patch_manager");
53
53
  const init_patch_1 = require("./init_patch");
54
- let browser, wapiInjected = false, dumbCache = undefined, wapiAttempts = 1;
54
+ let browser, wapiInjected = false, pageCache = undefined, wapiAttempts = 1;
55
55
  exports.BROWSER_START_TS = 0;
56
56
  function initPage(sessionId, config, qrManager, customUserAgent, spinner, _page, skipAuth) {
57
57
  var _a, _b, _c, _d, _e;
@@ -132,32 +132,50 @@ function initPage(sessionId, config, qrManager, customUserAgent, spinner, _page,
132
132
  if (proxyAddr) {
133
133
  proxy = (yield Promise.resolve().then(() => __importStar(require('smashah-puppeteer-page-proxy')))).default;
134
134
  }
135
+ /**
136
+ * Detect a locally cached page
137
+ */
138
+ if (process.env.WA_LOCAL_PAGE_CACHE) {
139
+ const localPageCacheExists = yield (0, tools_1.pathExists)(process.env.WA_LOCAL_PAGE_CACHE, true);
140
+ logging_1.log.info(`Local page cache env var set: ${process.env.WA_LOCAL_PAGE_CACHE} ${localPageCacheExists}`);
141
+ if (localPageCacheExists) {
142
+ logging_1.log.info(`Local page cache file exists. Loading...`);
143
+ pageCache = yield fs.readFile(process.env.WA_LOCAL_PAGE_CACHE, "utf8");
144
+ }
145
+ }
135
146
  if (interceptAuthentication || proxyAddr || blockCrashLogs || true) {
136
147
  yield waPage.setRequestInterception(true);
137
148
  waPage.on('response', (response) => __awaiter(this, void 0, void 0, function* () {
138
149
  try {
139
150
  if (response.request().url() == "https://web.whatsapp.com/") {
140
151
  const t = yield response.text();
141
- if (t.includes(`class="no-js"`) && t.includes(`self.`) && !dumbCache) {
152
+ if (t.includes(`class="no-js"`) && t.includes(`self.`) && !pageCache) {
142
153
  //this is a valid response, save it for later
143
- dumbCache = t;
154
+ pageCache = t;
144
155
  logging_1.log.info("saving valid page to dumb cache");
156
+ /**
157
+ * Save locally
158
+ */
159
+ if (process.env.WA_LOCAL_PAGE_CACHE) {
160
+ logging_1.log.info(`Writing page cache to local file: ${process.env.WA_LOCAL_PAGE_CACHE}`);
161
+ yield fs.writeFile(process.env.WA_LOCAL_PAGE_CACHE, pageCache);
162
+ }
145
163
  }
146
164
  }
147
165
  }
148
166
  catch (error) {
149
- logging_1.log.error("dumb cache error", error);
167
+ logging_1.log.error("page cache error", error);
150
168
  }
151
169
  }));
152
170
  const authCompleteEv = new events_1.EvEmitter(sessionId, 'AUTH');
153
171
  waPage.on('request', (request) => __awaiter(this, void 0, void 0, function* () {
154
172
  //local refresh cache:
155
- if (request.url() === "https://web.whatsapp.com/" && dumbCache) {
156
- //if the dumbCache isn't set and this response includes
157
- logging_1.log.info("reviving page from dumb cache");
173
+ if (request.url() === "https://web.whatsapp.com/" && pageCache) {
174
+ //if the pageCache isn't set and this response includes
175
+ logging_1.log.info("reviving page from page cache");
158
176
  return yield request.respond({
159
177
  status: 200,
160
- body: dumbCache
178
+ body: pageCache
161
179
  });
162
180
  }
163
181
  if (interceptAuthentication &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.52.0",
3
+ "version": "4.52.1",
4
4
  "licenseCheckUrl": "https://funcs.openwa.dev/license-check",
5
5
  "brokenMethodReportUrl": "https://funcs.openwa.dev/report-bm",
6
6
  "patches": "https://cdn.openwa.dev/patches.json",