coffeeinabit 0.0.23 → 0.0.26

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.
@@ -1,4 +1,4 @@
1
- import { firefox } from 'playwright';
1
+ import { chromium } from 'playwright';
2
2
  import path from 'path';
3
3
  import fs from 'fs';
4
4
  import { getContextDirectory } from './tools/context_paths.js';
@@ -369,9 +369,23 @@ export class LinkedInAutomation {
369
369
  this.emitStatus();
370
370
 
371
371
  if (this.originalHeadless && this.needsManualLogin) {
372
- console.log('[LinkedInAutomation] Manual login completed. Switching back to headless mode...');
372
+ console.log('[LinkedInAutomation] Manual login completed. Waiting for session to be saved...');
373
373
  clearInterval(pollInterval);
374
374
 
375
+ await this.waitRandom(5000, 7000);
376
+
377
+ const storageStatePath = this.getStorageStatePath();
378
+ try {
379
+ await this.context.storageState({ path: storageStatePath });
380
+ const cookies = await this.context.cookies();
381
+ console.log(`[LinkedInAutomation] Saved storage state with ${cookies.length} cookies to: ${storageStatePath}`);
382
+ } catch (error) {
383
+ console.error('[LinkedInAutomation] Error saving storage state:', error.message);
384
+ }
385
+
386
+ await this.waitRandom(3000, 5000);
387
+
388
+ console.log('[LinkedInAutomation] Switching back to headless mode...');
375
389
  this.status = 'switching_to_headless';
376
390
  this.emitStatus();
377
391
 
@@ -423,7 +437,24 @@ export class LinkedInAutomation {
423
437
  }
424
438
 
425
439
  if (this.context) {
426
- await this.context.close();
440
+ try {
441
+ const storageStatePath = this.getStorageStatePath();
442
+ const cookies = await this.context.cookies();
443
+ if (cookies.length > 0) {
444
+ await this.context.storageState({ path: storageStatePath });
445
+ console.log(`[LinkedInAutomation] Saved storage state with ${cookies.length} cookies to: ${storageStatePath}`);
446
+ }
447
+ await this.context.close();
448
+ await this.waitRandom(3000, 5000);
449
+ } catch (error) {
450
+ console.error('[LinkedInAutomation] Error saving storage state before close:', error.message);
451
+ try {
452
+ await this.context.close();
453
+ await this.waitRandom(3000, 5000);
454
+ } catch (closeError) {
455
+ console.error('[LinkedInAutomation] Error closing context:', closeError.message);
456
+ }
457
+ }
427
458
  this.context = null;
428
459
  this.browser = null;
429
460
  }
@@ -910,12 +941,18 @@ export class LinkedInAutomation {
910
941
  return this._currentAccessToken || null;
911
942
  }
912
943
 
944
+ getStorageStatePath() {
945
+ const sanitizedEmail = this.userEmail?.replace(/[^a-zA-Z0-9]/g, '_') || 'default_user';
946
+ return path.join(this.linkedInSessionDir, `storage_state_${sanitizedEmail}.json`);
947
+ }
948
+
913
949
  async launchBrowserAndLogin() {
914
- console.log('[LinkedInAutomation] Launching Firefox with persistent context for LinkedIn login...');
950
+ console.log('[LinkedInAutomation] Launching Chromium with persistent context for LinkedIn login...');
915
951
 
916
952
  this.userEmail = this._currentUserEmail || 'default_user';
917
953
  const sanitizedEmail = this.userEmail.replace(/[^a-zA-Z0-9]/g, '_');
918
954
  const userDataPath = path.join(this.linkedInSessionDir, `linkedin_auth_${sanitizedEmail}`);
955
+ const storageStatePath = this.getStorageStatePath();
919
956
 
920
957
  console.log('[LinkedInAutomation] User data path:', userDataPath);
921
958
 
@@ -927,10 +964,16 @@ export class LinkedInAutomation {
927
964
  const launchOptions = {
928
965
  headless: this.headless || false,
929
966
  viewport: null,
930
- ignoreHTTPSErrors: true
967
+ ignoreHTTPSErrors: true,
968
+ args: [
969
+ '--disable-blink-features=AutomationControlled',
970
+ '--disable-dev-shm-usage',
971
+ '--no-sandbox',
972
+ '--disable-setuid-sandbox'
973
+ ]
931
974
  };
932
975
 
933
- this.context = await firefox.launchPersistentContext(userDataPath, launchOptions);
976
+ this.context = await chromium.launchPersistentContext(userDataPath, launchOptions);
934
977
 
935
978
  console.log('[LinkedInAutomation] Persistent context launched successfully');
936
979
 
@@ -938,6 +981,23 @@ export class LinkedInAutomation {
938
981
 
939
982
  await this.enablePerformanceMode();
940
983
  await this.preparePrimaryPage();
984
+
985
+ if (fs.existsSync(storageStatePath)) {
986
+ try {
987
+ console.log('[LinkedInAutomation] Loading cookies from storage state file:', storageStatePath);
988
+ const storageState = JSON.parse(fs.readFileSync(storageStatePath, 'utf8'));
989
+ if (storageState.cookies && storageState.cookies.length > 0) {
990
+ await this.context.addCookies(storageState.cookies);
991
+ console.log(`[LinkedInAutomation] Added ${storageState.cookies.length} cookies from storage state file`);
992
+ }
993
+ } catch (error) {
994
+ console.error('[LinkedInAutomation] Error loading storage state:', error.message);
995
+ }
996
+ }
997
+
998
+ const cookiesAfterLaunch = await this.context.cookies();
999
+ console.log(`[LinkedInAutomation] Total ${cookiesAfterLaunch.length} cookies in context`);
1000
+
941
1001
  // await this.installCursorHighlight();
942
1002
 
943
1003
  console.log('[LinkedInAutomation] Checking if user is already authenticated...');
@@ -1001,15 +1061,45 @@ export class LinkedInAutomation {
1001
1061
  const sanitizedEmail = this.userEmail.replace(/[^a-zA-Z0-9]/g, '_');
1002
1062
  const userDataPath = path.join(this.linkedInSessionDir, `linkedin_auth_${sanitizedEmail}`);
1003
1063
 
1064
+ const storageStatePath = this.getStorageStatePath();
1065
+ try {
1066
+ await this.context.storageState({ path: storageStatePath });
1067
+ const cookies = await this.context.cookies();
1068
+ console.log(`[LinkedInAutomation] Saved storage state with ${cookies.length} cookies before mode switch`);
1069
+ } catch (error) {
1070
+ console.error('[LinkedInAutomation] Error saving storage state:', error);
1071
+ }
1072
+
1004
1073
  await this.context.close();
1074
+ await this.waitRandom(3000, 5000);
1005
1075
 
1006
1076
  this.headless = newHeadless;
1007
1077
 
1008
- this.context = await firefox.launchPersistentContext(userDataPath, {
1078
+ const launchOptions = {
1009
1079
  headless: this.headless,
1010
1080
  viewport: null,
1011
- ignoreHTTPSErrors: true
1012
- });
1081
+ ignoreHTTPSErrors: true,
1082
+ args: [
1083
+ '--disable-blink-features=AutomationControlled',
1084
+ '--disable-dev-shm-usage',
1085
+ '--no-sandbox',
1086
+ '--disable-setuid-sandbox'
1087
+ ]
1088
+ };
1089
+
1090
+ this.context = await chromium.launchPersistentContext(userDataPath, launchOptions);
1091
+
1092
+ if (fs.existsSync(storageStatePath)) {
1093
+ try {
1094
+ const storageState = JSON.parse(fs.readFileSync(storageStatePath, 'utf8'));
1095
+ if (storageState.cookies && storageState.cookies.length > 0) {
1096
+ await this.context.addCookies(storageState.cookies);
1097
+ console.log(`[LinkedInAutomation] Added ${storageState.cookies.length} cookies from storage state for mode switch`);
1098
+ }
1099
+ } catch (error) {
1100
+ console.error('[LinkedInAutomation] Error loading storage state for mode switch:', error.message);
1101
+ }
1102
+ }
1013
1103
 
1014
1104
  this.browser = this.context;
1015
1105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coffeeinabit",
3
- "version": "0.0.23",
3
+ "version": "0.0.26",
4
4
  "description": "CoffeeInABit App",
5
5
  "main": "server.js",
6
6
  "type": "module",
@@ -17,7 +17,8 @@
17
17
  },
18
18
  "scripts": {
19
19
  "start": "node server.js",
20
- "dev": "nodemon server.js"
20
+ "dev": "nodemon server.js",
21
+ "postinstall": "npx playwright install chromium"
21
22
  },
22
23
  "dependencies": {
23
24
  "axios": "^1.6.0",
package/server.js CHANGED
@@ -17,13 +17,6 @@ dotenv.config();
17
17
  const __filename = fileURLToPath(import.meta.url);
18
18
  const __dirname = path.dirname(__filename);
19
19
 
20
- try {
21
- execSync('npx playwright install firefox', { stdio: 'inherit' });
22
- console.log('[Server] Playwright Firefox browser installed/verified');
23
- } catch (error) {
24
- console.warn('[Server] Warning: Could not install Playwright Firefox browser:', error.message);
25
- }
26
-
27
20
  const FileStoreSession = FileStore(session);
28
21
 
29
22
  const app = express();
@@ -298,6 +298,10 @@ export async function executeGetMessages(page, action) {
298
298
  }
299
299
 
300
300
  console.log('[get_messages] Successfully extracted messages');
301
+
302
+ console.log('[get_messages] Closing all conversation bubbles');
303
+ await closeAllConversationBubbles(page);
304
+
301
305
  return {
302
306
  action: 'get_messages',
303
307
  result: { status: 'success', message: messageData.content, items: messageData.items },