Skip to content

Commit 3520ddc

Browse files
authored
Merge pull request #388 from getmaxun/revert-386-browser-fix
Revert "fix: prevent page reload on run trigger to open remote browser"
2 parents 85b4786 + 153cf81 commit 3520ddc

File tree

5 files changed

+9
-102
lines changed

5 files changed

+9
-102
lines changed

server/src/browser-management/classes/BrowserPool.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ interface BrowserPoolInfo {
1515
* @default false
1616
*/
1717
active: boolean,
18-
19-
isRobotRun?: boolean;
2018
}
2119

2220
/**
@@ -48,29 +46,17 @@ export class BrowserPool {
4846
* @param browser remote browser instance
4947
* @param active states if the browser's instance is being actively used
5048
*/
51-
public addRemoteBrowser = (id: string, browser: RemoteBrowser, active: boolean = false, isRobotRun: boolean = false): void => {
49+
public addRemoteBrowser = (id: string, browser: RemoteBrowser, active: boolean = false): void => {
5250
this.pool = {
5351
...this.pool,
5452
[id]: {
5553
browser,
5654
active,
57-
isRobotRun
5855
},
5956
}
6057
logger.log('debug', `Remote browser with id: ${id} added to the pool`);
6158
};
6259

63-
public hasActiveRobotRun(): boolean {
64-
return Object.values(this.pool).some(info => info.isRobotRun);
65-
}
66-
67-
public clearRobotRunState(id: string): void {
68-
if (this.pool[id]) {
69-
this.pool[id].isRobotRun = false;
70-
logger.log('debug', `Robot run state cleared for browser ${id}`);
71-
}
72-
}
73-
7460
/**
7561
* Removes the remote browser instance from the pool.
7662
* @param id remote browser instance's id
@@ -81,8 +67,6 @@ export class BrowserPool {
8167
logger.log('warn', `Remote browser with id: ${id} does not exist in the pool`);
8268
return false;
8369
}
84-
85-
this.clearRobotRunState(id);
8670
delete (this.pool[id]);
8771
logger.log('debug', `Remote browser with id: ${id} deleted from the pool`);
8872
return true;

server/src/browser-management/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const createRemoteBrowserForRun = (userId: string): string => {
5959
async (socket: Socket) => {
6060
const browserSession = new RemoteBrowser(socket);
6161
await browserSession.initialize(userId);
62-
browserPool.addRemoteBrowser(id, browserSession, true, true);
62+
browserPool.addRemoteBrowser(id, browserSession, true);
6363
socket.emit('ready-for-run');
6464
});
6565
return id;

server/src/routes/record.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import stealthPlugin from 'puppeteer-extra-plugin-stealth';
1616
import logger from "../logger";
1717
import { getDecryptedProxyConfig } from './proxy';
1818
import { requireSignIn } from '../middlewares/auth';
19-
import { browserPool } from '../server';
2019

2120
export const router = Router();
2221
chromium.use(stealthPlugin());
@@ -34,17 +33,6 @@ router.all('/', requireSignIn, (req, res, next) => {
3433
next() // pass control to the next handler
3534
})
3635

37-
router.use('/', requireSignIn, (req: AuthenticatedRequest, res: Response, next) => {
38-
if (browserPool.hasActiveRobotRun()) {
39-
logger.log('debug', 'Preventing browser initialization - robot run in progress');
40-
return res.status(403).json({
41-
error: 'Cannot initialize recording browser while a robot run is in progress'
42-
});
43-
}
44-
next();
45-
});
46-
47-
4836
/**
4937
* GET endpoint for starting the remote browser recording session.
5038
* returns session's id

server/src/workflow-management/classes/Interpreter.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,6 @@ export class WorkflowInterpreter {
332332
}, {})
333333
}
334334

335-
this.socket.emit('run-completed', "success");
336-
337335
logger.log('debug', `Interpretation finished`);
338336
this.clearState();
339337
return result;

src/pages/MainPage.tsx

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,13 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
6868
const readyForRunHandler = useCallback((browserId: string, runId: string) => {
6969
interpretStoredRecording(runId).then(async (interpretation: boolean) => {
7070
if (!aborted) {
71-
// if (interpretation) {
72-
// notify('success', t('main_page.notifications.interpretation_success', { name: runningRecordingName }));
73-
// } else {
74-
// notify('success', t('main_page.notifications.interpretation_failed', { name: runningRecordingName }));
75-
// // destroy the created browser
76-
// await stopRecording(browserId);
77-
// }
78-
if (!interpretation) await stopRecording(browserId);
71+
if (interpretation) {
72+
notify('success', t('main_page.notifications.interpretation_success', { name: runningRecordingName }));
73+
} else {
74+
notify('success', t('main_page.notifications.interpretation_failed', { name: runningRecordingName }));
75+
// destroy the created browser
76+
await stopRecording(browserId);
77+
}
7978
}
8079
setRunningRecordingName('');
8180
setCurrentInterpretationLog('');
@@ -90,12 +89,6 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
9089

9190
const handleRunRecording = useCallback((settings: RunSettings) => {
9291
createRunForStoredRecording(runningRecordingId, settings).then(({ browserId, runId }: CreateRunResponse) => {
93-
localStorage.setItem('runInfo', JSON.stringify({
94-
browserId,
95-
runId,
96-
recordingName: runningRecordingName
97-
}));
98-
9992
setIds({ browserId, runId });
10093
const socket =
10194
io(`${apiUrl}/${browserId}`, {
@@ -105,18 +98,6 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
10598
setSockets(sockets => [...sockets, socket]);
10699
socket.on('ready-for-run', () => readyForRunHandler(browserId, runId));
107100
socket.on('debugMessage', debugMessageHandler);
108-
109-
socket.on('run-completed', (status) => {
110-
if (status === 'success') {
111-
notify('success', t('main_page.notifications.interpretation_success', { name: runningRecordingName }));
112-
} else {
113-
notify('error', t('main_page.notifications.interpretation_failed', { name: runningRecordingName }));
114-
}
115-
setRunningRecordingName('');
116-
setCurrentInterpretationLog('');
117-
setRerenderRuns(true);
118-
});
119-
120101
setContent('runs');
121102
if (browserId) {
122103
notify('info', t('main_page.notifications.run_started', { name: runningRecordingName }));
@@ -127,7 +108,6 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
127108
return (socket: Socket, browserId: string, runId: string) => {
128109
socket.off('ready-for-run', () => readyForRunHandler(browserId, runId));
129110
socket.off('debugMessage', debugMessageHandler);
130-
socket.off('run-completed');
131111
}
132112
}, [runningRecordingName, sockets, ids, readyForRunHandler, debugMessageHandler])
133113

@@ -142,49 +122,6 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
142122
});
143123
}
144124

145-
useEffect(() => {
146-
const storedRunInfo = localStorage.getItem('runInfo');
147-
console.log('storedRunInfo', storedRunInfo);
148-
149-
if (storedRunInfo) {
150-
// Parse the stored info
151-
const { browserId, runId, recordingName } = JSON.parse(storedRunInfo);
152-
153-
// Reconnect to the specific browser's namespace
154-
setIds({ browserId, runId });
155-
const socket = io(`${apiUrl}/${browserId}`, {
156-
transports: ["websocket"],
157-
rejectUnauthorized: false
158-
});
159-
160-
// Update component state with stored info
161-
setRunningRecordingName(recordingName);
162-
setSockets(sockets => [...sockets, socket]);
163-
164-
// Set up event listeners
165-
socket.on('ready-for-run', () => readyForRunHandler(browserId, runId));
166-
socket.on('debugMessage', debugMessageHandler);
167-
socket.on('run-completed', (status) => {
168-
if (status === 'success') {
169-
notify('success', t('main_page.notifications.interpretation_success', { name: recordingName }));
170-
} else {
171-
notify('error', t('main_page.notifications.interpretation_failed', { name: recordingName }));
172-
}
173-
setRunningRecordingName('');
174-
setCurrentInterpretationLog('');
175-
setRerenderRuns(true);
176-
localStorage.removeItem('runInfo'); // Clean up stored info
177-
});
178-
179-
// Cleanup function
180-
return () => {
181-
socket.off('ready-for-run', () => readyForRunHandler(browserId, runId));
182-
socket.off('debugMessage', debugMessageHandler);
183-
socket.off('run-completed');
184-
};
185-
}
186-
}, []);
187-
188125
const DisplayContent = () => {
189126
switch (content) {
190127
case 'robots':

0 commit comments

Comments
 (0)