coffeeinabit 0.0.5 → 0.0.6
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/linkedin_automation.js +52 -0
- package/package.json +7 -2
- package/public/dashboard.html +31 -7
- package/server.js +20 -0
package/linkedin_automation.js
CHANGED
|
@@ -719,6 +719,58 @@ export class LinkedInAutomation {
|
|
|
719
719
|
}
|
|
720
720
|
}
|
|
721
721
|
|
|
722
|
+
async updateBrowserVisibility(keepBrowser) {
|
|
723
|
+
if (!this.browser || !this.isRunning) {
|
|
724
|
+
console.log('[LinkedInAutomation] Browser not running, cannot update visibility');
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
try {
|
|
729
|
+
const newHeadless = !keepBrowser;
|
|
730
|
+
|
|
731
|
+
if (this.headless === newHeadless) {
|
|
732
|
+
console.log('[LinkedInAutomation] Browser visibility already matches setting');
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
console.log(`[LinkedInAutomation] Updating browser visibility: ${keepBrowser ? 'visible' : 'headless'}`);
|
|
737
|
+
|
|
738
|
+
const currentUrl = this.page.url();
|
|
739
|
+
const currentTitle = await this.page.title();
|
|
740
|
+
|
|
741
|
+
await this.browser.close();
|
|
742
|
+
|
|
743
|
+
this.headless = newHeadless;
|
|
744
|
+
this.browser = await firefox.launch({ headless: this.headless });
|
|
745
|
+
|
|
746
|
+
this.context = await this.browser.newContext({
|
|
747
|
+
viewport: null,
|
|
748
|
+
ignoreHTTPSErrors: true
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
await this.enablePerformanceMode();
|
|
752
|
+
this.page = await this.context.newPage();
|
|
753
|
+
|
|
754
|
+
await this.page.goto(currentUrl, {
|
|
755
|
+
waitUntil: 'domcontentloaded',
|
|
756
|
+
timeout: 30000
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
this.setupPageListeners();
|
|
760
|
+
|
|
761
|
+
console.log('[LinkedInAutomation] Browser visibility updated successfully');
|
|
762
|
+
|
|
763
|
+
this.io.emit('automation_status', {
|
|
764
|
+
status: 'running',
|
|
765
|
+
message: `Browser is now ${keepBrowser ? 'visible' : 'running in headless mode'}`
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
} catch (error) {
|
|
769
|
+
console.error('[LinkedInAutomation] Failed to update browser visibility:', error);
|
|
770
|
+
throw error;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
722
774
|
async checkAndVerifySession() {
|
|
723
775
|
try {
|
|
724
776
|
console.log('[LinkedInAutomation] Navigating to LinkedIn feed to verify session...');
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coffeeinabit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "CoffeeInABit App",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"keywords": [
|
|
7
|
+
"keywords": [
|
|
8
|
+
"automation",
|
|
9
|
+
"linkedin",
|
|
10
|
+
"windows",
|
|
11
|
+
"playwright"
|
|
12
|
+
],
|
|
8
13
|
"author": "Azam Alamov <azam.alamov@icloud.com>",
|
|
9
14
|
"license": "MIT",
|
|
10
15
|
"bin": {
|
package/public/dashboard.html
CHANGED
|
@@ -205,16 +205,40 @@
|
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
function toggleKeepBrowser() {
|
|
208
|
+
async function toggleKeepBrowser() {
|
|
209
209
|
const keepBrowserToggle = document.getElementById('keepBrowserToggle');
|
|
210
210
|
const isKeepBrowser = keepBrowserToggle.checked;
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
212
|
+
localStorage.setItem('keepBrowser', isKeepBrowser.toString());
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
const response = await fetch('/api/automation/settings', {
|
|
216
|
+
method: 'POST',
|
|
217
|
+
headers: {
|
|
218
|
+
'Content-Type': 'application/json'
|
|
219
|
+
},
|
|
220
|
+
body: JSON.stringify({
|
|
221
|
+
keepBrowser: isKeepBrowser
|
|
222
|
+
})
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
const data = await response.json();
|
|
226
|
+
|
|
227
|
+
if (data.success) {
|
|
228
|
+
if (isKeepBrowser) {
|
|
229
|
+
showAlert('success', 'Browser is now visible');
|
|
230
|
+
} else {
|
|
231
|
+
showAlert('success', 'Browser is now running in headless mode');
|
|
232
|
+
}
|
|
233
|
+
} else {
|
|
234
|
+
showAlert('error', data.error || 'Failed to update browser setting');
|
|
235
|
+
keepBrowserToggle.checked = !isKeepBrowser;
|
|
236
|
+
localStorage.setItem('keepBrowser', (!isKeepBrowser).toString());
|
|
237
|
+
}
|
|
238
|
+
} catch (error) {
|
|
239
|
+
showAlert('error', 'Error updating browser setting: ' + error.message);
|
|
240
|
+
keepBrowserToggle.checked = !isKeepBrowser;
|
|
241
|
+
localStorage.setItem('keepBrowser', (!isKeepBrowser).toString());
|
|
218
242
|
}
|
|
219
243
|
}
|
|
220
244
|
|
package/server.js
CHANGED
|
@@ -173,6 +173,26 @@ app.get('/api/automation/status', (req, res) => {
|
|
|
173
173
|
res.json(linkedinAutomation.getStatus());
|
|
174
174
|
});
|
|
175
175
|
|
|
176
|
+
app.post('/api/automation/settings', async (req, res) => {
|
|
177
|
+
if (!cloudAuth.isAuthenticated(req.session)) {
|
|
178
|
+
return res.status(401).json({ error: 'Authentication required' });
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
const { keepBrowser } = req.body;
|
|
183
|
+
|
|
184
|
+
if (typeof keepBrowser !== 'boolean') {
|
|
185
|
+
return res.status(400).json({ error: 'keepBrowser must be a boolean' });
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
await linkedinAutomation.updateBrowserVisibility(keepBrowser);
|
|
189
|
+
res.json({ success: true, message: 'Browser visibility setting updated' });
|
|
190
|
+
} catch (error) {
|
|
191
|
+
console.error('[Server] Failed to update browser settings:', error);
|
|
192
|
+
res.status(500).json({ error: error.message });
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
176
196
|
io.on('connection', (socket) => {
|
|
177
197
|
console.log('[Server] Client connected:', socket.id);
|
|
178
198
|
|