Skip to content

Commit 305dee1

Browse files
authored
Merge pull request #375 from RohitR311/cred-fix
feat: change credentials based on input type
2 parents c0af7fa + 1950cc5 commit 305dee1

File tree

5 files changed

+321
-160
lines changed

5 files changed

+321
-160
lines changed

maxun-core/src/interpret.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,14 @@ export default class Interpreter extends EventEmitter {
490490

491491
const executeAction = async (invokee: any, methodName: string, args: any) => {
492492
console.log("Executing action:", methodName, args);
493+
494+
if (methodName === 'press' || methodName === 'type') {
495+
// Extract only the first two arguments for these methods
496+
const limitedArgs = Array.isArray(args) ? args.slice(0, 2) : [args];
497+
await (<any>invokee[methodName])(...limitedArgs);
498+
return;
499+
}
500+
493501
if (!args || Array.isArray(args)) {
494502
await (<any>invokee[methodName])(...(args ?? []));
495503
} else {

server/src/routes/storage.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,48 +154,52 @@ function formatRunResponse(run: any) {
154154
return formattedRun;
155155
}
156156

157-
interface CredentialUpdate {
158-
[selector: string]: string;
157+
interface CredentialInfo {
158+
value: string;
159+
type: string;
159160
}
160161

161-
function updateTypeActionsInWorkflow(workflow: any[], credentials: CredentialUpdate) {
162+
interface Credentials {
163+
[key: string]: CredentialInfo;
164+
}
165+
166+
function updateTypeActionsInWorkflow(workflow: any[], credentials: Credentials) {
162167
return workflow.map(step => {
163168
if (!step.what) return step;
164169

165-
// First pass: mark indices to remove
166170
const indicesToRemove = new Set<number>();
167-
step.what.forEach((action: any, index: any) => {
171+
step.what.forEach((action: any, index: number) => {
168172
if (!action.action || !action.args?.[0]) return;
169173

170-
// If it's a type/press action for a credential
171174
if ((action.action === 'type' || action.action === 'press') && credentials[action.args[0]]) {
172175
indicesToRemove.add(index);
173-
// Check if next action is waitForLoadState
176+
174177
if (step.what[index + 1]?.action === 'waitForLoadState') {
175178
indicesToRemove.add(index + 1);
176179
}
177180
}
178181
});
179182

180-
// Filter out marked indices and create new what array
181-
const filteredWhat = step.what.filter((_: any, index: any) => !indicesToRemove.has(index));
183+
const filteredWhat = step.what.filter((_: any, index: number) => !indicesToRemove.has(index));
182184

183-
// Add new type actions after click actions
184-
Object.entries(credentials).forEach(([selector, credential]) => {
185+
Object.entries(credentials).forEach(([selector, credentialInfo]) => {
185186
const clickIndex = filteredWhat.findIndex((action: any) =>
186187
action.action === 'click' && action.args?.[0] === selector
187188
);
188189

189190
if (clickIndex !== -1) {
190-
const chars = credential.split('');
191+
const chars = credentialInfo.value.split('');
192+
191193
chars.forEach((char, i) => {
192-
// Add type action
193194
filteredWhat.splice(clickIndex + 1 + (i * 2), 0, {
194195
action: 'type',
195-
args: [selector, encrypt(char)]
196+
args: [
197+
selector,
198+
encrypt(char),
199+
credentialInfo.type
200+
]
196201
});
197202

198-
// Add waitForLoadState
199203
filteredWhat.splice(clickIndex + 2 + (i * 2), 0, {
200204
action: 'waitForLoadState',
201205
args: ['networkidle']

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,14 +474,18 @@ export class WorkflowGenerator {
474474
public onKeyboardInput = async (key: string, coordinates: Coordinates, page: Page) => {
475475
let where: WhereWhatPair["where"] = { url: this.getBestUrl(page.url()) };
476476
const selector = await this.generateSelector(page, coordinates, ActionType.Keydown);
477+
478+
const elementInfo = await getElementInformation(page, coordinates, '', false);
479+
const inputType = elementInfo?.attributes?.type || "text";
480+
477481
if (selector) {
478482
where.selectors = [selector];
479483
}
480484
const pair: WhereWhatPair = {
481485
where,
482486
what: [{
483487
action: 'press',
484-
args: [selector, encrypt(key)],
488+
args: [selector, encrypt(key), inputType],
485489
}],
486490
}
487491
if (selector) {
@@ -992,6 +996,7 @@ export class WorkflowGenerator {
992996
let input = {
993997
selector: '',
994998
value: '',
999+
type: '',
9951000
actionCounter: 0,
9961001
};
9971002

@@ -1006,7 +1011,7 @@ export class WorkflowGenerator {
10061011
// when more than one press action is present, add a type action
10071012
pair.what.splice(index - input.actionCounter, input.actionCounter, {
10081013
action: 'type',
1009-
args: [input.selector, encrypt(input.value)],
1014+
args: [input.selector, encrypt(input.value), input.type],
10101015
}, {
10111016
action: 'waitForLoadState',
10121017
args: ['networkidle'],
@@ -1034,13 +1039,14 @@ export class WorkflowGenerator {
10341039
action: 'waitForLoadState',
10351040
args: ['networkidle'],
10361041
})
1037-
input = { selector: '', value: '', actionCounter: 0 };
1042+
input = { selector: '', value: '', type: '', actionCounter: 0 };
10381043
}
10391044
} else {
10401045
pushTheOptimizedAction(pair, index);
10411046
input = {
10421047
selector: condition.args[0],
10431048
value: condition.args[1],
1049+
type: condition.args[2],
10441050
actionCounter: 1,
10451051
};
10461052
}
@@ -1049,7 +1055,7 @@ export class WorkflowGenerator {
10491055
if (input.value.length !== 0) {
10501056
pushTheOptimizedAction(pair, index);
10511057
// clear the input
1052-
input = { selector: '', value: '', actionCounter: 0 };
1058+
input = { selector: '', value: '', type: '', actionCounter: 0 };
10531059
}
10541060
}
10551061
});

src/api/storage.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ import { ScheduleSettings } from "../components/robot/ScheduleSettings";
55
import { CreateRunResponse, ScheduleRunResponse } from "../pages/MainPage";
66
import { apiUrl } from "../apiConfig";
77

8+
interface CredentialInfo {
9+
value: string;
10+
type: string;
11+
}
12+
813
interface Credentials {
9-
[key: string]: string;
14+
[key: string]: CredentialInfo;
1015
}
1116

1217
export const getStoredRecordings = async (): Promise<string[] | null> => {

0 commit comments

Comments
 (0)