repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
dockge | github_2023 | louislam | typescript | DockgeServer.initDataDir | initDataDir() {
if (! fs.existsSync(this.config.dataDir)) {
fs.mkdirSync(this.config.dataDir, { recursive: true });
}
// Check if a directory
if (!fs.lstatSync(this.config.dataDir).isDirectory()) {
throw new Error(`Fatal error: ${this.config.dataDir} is not a dir... | /**
* Initialize the data directory
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/dockge-server.ts#L541-L557 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | DockgeServer.initJWTSecret | async initJWTSecret() : Promise<Bean> {
let jwtSecretBean = await R.findOne("setting", " `key` = ? ", [
"jwtSecret",
]);
if (!jwtSecretBean) {
jwtSecretBean = R.dispense("setting");
jwtSecretBean.key = "jwtSecret";
}
jwtSecretBean.value = gen... | /**
* Init or reset JWT secret
* @returns JWT secret
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/dockge-server.ts#L563-L576 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | DockgeServer.sendStackList | async sendStackList(useCache = false) {
let socketList = this.io.sockets.sockets.values();
let stackList;
for (let socket of socketList) {
let dockgeSocket = socket as DockgeSocket;
// Check if the room is a number (user id)
if (dockgeSocket.userID) {
... | /**
* Send stack list to all connected sockets
* @param useCache
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/dockge-server.ts#L582-L611 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | DockgeServer.shutdownFunction | async shutdownFunction(signal : string | undefined) {
log.info("server", "Shutdown requested");
log.info("server", "Called signal: " + signal);
// TODO: Close all terminals?
await Database.close();
Settings.stopCacheCleaner();
} | /**
* Shutdown the application
* Stops all monitors and closes the database connection.
* @param signal The signal that triggered this function to be called.
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/dockge-server.ts#L643-L651 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | DockgeServer.finalFunction | finalFunction() {
log.info("server", "Graceful shutdown successful!");
} | /**
* Final function called before application exits
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/dockge-server.ts#L656-L658 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | DockgeServer.disconnectAllSocketClients | disconnectAllSocketClients(userID: number | undefined, currentSocketID? : string) {
for (const rawSocket of this.io.sockets.sockets.values()) {
let socket = rawSocket as DockgeSocket;
if ((!userID || socket.userID === userID) && socket.id !== currentSocketID) {
try {
... | /**
* Force connected sockets of a user to refresh and disconnect.
* Used for resetting password.
* @param {string} userID
* @param {string?} currentSocketID
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/dockge-server.ts#L666-L678 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Logger.constructor | constructor() {
if (typeof process !== "undefined" && process.env.DOCKGE_HIDE_LOG) {
const list = process.env.DOCKGE_HIDE_LOG.split(",").map(v => v.toLowerCase());
for (const pair of list) {
// split first "_" only
const values = pair.split(/_(.*)/s);
... | /**
*
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/log.ts#L81-L97 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Logger.log | log(module: string, msg: unknown, level: string) {
if (level === "DEBUG" && !isDev) {
return;
}
if (this.hideLog[level] && this.hideLog[level].includes(module.toLowerCase())) {
return;
}
module = module.toUpperCase();
level = level.toUpperCase();... | /**
* Write a message to the log
* @param module The module the log comes from
* @param msg Message to write
* @param level Log level. One of INFO, WARN, ERROR, DEBUG or can be customized.
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/log.ts#L105-L157 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Logger.info | info(module: string, msg: unknown) {
this.log(module, msg, "info");
} | /**
* Log an INFO message
* @param module Module log comes from
* @param msg Message to write
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/log.ts#L164-L166 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Logger.warn | warn(module: string, msg: unknown) {
this.log(module, msg, "warn");
} | /**
* Log a WARN message
* @param module Module log comes from
* @param msg Message to write
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/log.ts#L173-L175 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Logger.error | error(module: string, msg: unknown) {
this.log(module, msg, "error");
} | /**
* Log an ERROR message
* @param module Module log comes from
* @param msg Message to write
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/log.ts#L182-L184 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Logger.debug | debug(module: string, msg: unknown) {
this.log(module, msg, "debug");
} | /**
* Log a DEBUG message
* @param module Module log comes from
* @param msg Message to write
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/log.ts#L191-L193 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Logger.exception | exception(module: string, exception: unknown, msg: unknown) {
let finalMessage = exception;
if (msg) {
finalMessage = `${msg}: ${exception}`;
}
this.log(module, finalMessage, "error");
} | /**
* Log an exception as an ERROR
* @param module Module log comes from
* @param exception The exception to include
* @param msg The message to write
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/log.ts#L201-L209 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | KumaRateLimiter.constructor | constructor(config : KumaRateLimiterOpts) {
this.errorMessage = config.errorMessage;
this.rateLimiter = new RateLimiter(config);
} | /**
* @param {object} config Rate limiter configuration object
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/rate-limiter.ts#L20-L23 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | KumaRateLimiter.pass | async pass(callback : KumaRateLimiterCallback, num = 1) {
const remainingRequests = await this.removeTokens(num);
log.info("rate-limit", "remaining requests: " + remainingRequests);
if (remainingRequests < 0) {
if (callback) {
callback({
ok: false,... | /**
* Should the request be passed through
* @param callback Callback function to call with decision
* @param {number} num Number of tokens to remove
* @returns {Promise<boolean>} Should the request be allowed?
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/rate-limiter.ts#L37-L50 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | KumaRateLimiter.removeTokens | async removeTokens(num = 1) {
return await this.rateLimiter.removeTokens(num);
} | /**
* Remove a given number of tokens
* @param {number} num Number of tokens to remove
* @returns {Promise<number>} Number of remaining tokens
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/rate-limiter.ts#L57-L59 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Settings.get | static async get(key : string) {
// Start cache clear if not started yet
if (!Settings.cacheCleaner) {
Settings.cacheCleaner = setInterval(() => {
log.debug("settings", "Cache Cleaner is just started.");
for (key in Settings.cacheList) {
i... | /**
* Retrieve value of setting based on key
* @param key Key of setting to retrieve
* @returns Value
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/settings.ts#L31-L71 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Settings.set | static async set(key : string, value : object | string | number | boolean, type : string | null = null) {
let bean = await R.findOne("setting", " `key` = ? ", [
key,
]);
if (!bean) {
bean = R.dispense("setting");
bean.key = key;
}
bean.type = ... | /**
* Sets the specified setting to specified value
* @param key Key of setting to set
* @param value Value to set to
* @param {?string} type Type of setting
* @returns {Promise<void>}
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/settings.ts#L80-L94 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Settings.getSettings | static async getSettings(type : string) {
const list = await R.getAll("SELECT `key`, `value` FROM setting WHERE `type` = ? ", [
type,
]);
const result : LooseObject = {};
for (const row of list) {
try {
result[row.key] = JSON.parse(row.value);
... | /**
* Get settings based on type
* @param type The type of setting
* @returns Settings
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/settings.ts#L101-L117 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Settings.setSettings | static async setSettings(type : string, data : LooseObject) {
const keyList = Object.keys(data);
const promiseList = [];
for (const key of keyList) {
let bean = await R.findOne("setting", " `key` = ? ", [
key
]);
if (bean == null) {
... | /**
* Set settings based on type
* @param type Type of settings to set
* @param data Values of settings
* @returns {Promise<void>}
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/settings.ts#L125-L150 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Settings.deleteCache | static deleteCache(keyList : string[]) {
for (const key of keyList) {
delete Settings.cacheList[key];
}
} | /**
* Delete selected keys from settings cache
* @param {string[]} keyList Keys to remove
* @returns {void}
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/settings.ts#L157-L161 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Settings.stopCacheCleaner | static stopCacheCleaner() {
if (Settings.cacheCleaner) {
clearInterval(Settings.cacheCleaner);
Settings.cacheCleaner = undefined;
}
} | /**
* Stop the cache cleaner if running
* @returns {void}
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/settings.ts#L167-L172 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Stack.ps | async ps() : Promise<object> {
let res = await childProcessAsync.spawn("docker", [ "compose", "ps", "--format", "json" ], {
cwd: this.path,
encoding: "utf-8",
});
if (!res.stdout) {
return {};
}
return JSON.parse(res.stdout.toString());
} | /**
* Get the status of the stack from `docker compose ps --format json`
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/stack.ts#L95-L104 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Stack.save | async save(isAdd : boolean) {
this.validate();
let dir = this.path;
// Check if the name is used if isAdd
if (isAdd) {
if (await fileExists(dir)) {
throw new ValidationError("Stack name already exists");
}
// Create the stack folder
... | /**
* Save the stack to the disk
* @param isAdd
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/stack.ts#L178-L207 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Stack.composeFileExists | static async composeFileExists(stacksDir : string, filename : string) : Promise<boolean> {
let filenamePath = path.join(stacksDir, filename);
// Check if any compose file exists
for (const filename of acceptedComposeFileNames) {
let composeFile = path.join(filenamePath, filename);
... | /**
* Checks if a compose file exists in the specified directory.
* @async
* @static
* @param {string} stacksDir - The directory of the stack.
* @param {string} filename - The name of the directory to check for the compose file.
* @returns {Promise<boolean>} A promise that resolves to a bo... | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/stack.ts#L253-L263 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Stack.getStatusList | static async getStatusList() : Promise<Map<string, number>> {
let statusList = new Map<string, number>();
let res = await childProcessAsync.spawn("docker", [ "compose", "ls", "--all", "--format", "json" ], {
encoding: "utf-8",
});
if (!res.stdout) {
return statu... | /**
* Get the status list, it will be used to update the status of the stacks
* Not all status will be returned, only the stack that is deployed or created to `docker compose` will be returned
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/stack.ts#L338-L356 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Stack.statusConvert | static statusConvert(status : string) : number {
if (status.startsWith("created")) {
return CREATED_STACK;
} else if (status.includes("exited")) {
// If one of the service is exited, we consider the stack is exited
return EXITED;
} else if (status.startsWith("... | /**
* Convert the status string from `docker compose ls` to the status number
* Input Example: "exited(1), running(1)"
* @param status
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/stack.ts#L363-L375 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Terminal.exit | protected exit = (res : {exitCode: number, signal?: number | undefined}) => {
for (const socketID in this.socketList) {
const socket = this.socketList[socketID];
socket.emitAgent("terminalExit", this.name, res.exitCode);
}
// Remove all clients
this.socketList = ... | /**
* Exit event handler
* @param res
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/terminal.ts | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Terminal.getBuffer | getBuffer() : string {
if (this.buffer.length === 0) {
return "";
}
return this.buffer.join("");
} | /**
* Get the terminal output string
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/terminal.ts#L196-L201 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | Terminal.getTerminal | public static getTerminal(name : string) : Terminal | undefined {
return Terminal.terminalMap.get(name);
} | /**
* Get a running and non-exited terminal
* @param name
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/terminal.ts#L213-L215 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | User.resetPassword | static async resetPassword(userID : number, newPassword : string) {
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
generatePasswordHash(newPassword),
userID
]);
} | /**
* Reset user password
* Fix #1510, as in the context reset-password.js, there is no auto model mapping. Call this static function instead.
* @param {number} userID ID of user to update
* @param {string} newPassword Users new password
* @returns {Promise<void>}
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/models/user.ts#L14-L19 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | User.resetPassword | async resetPassword(newPassword : string) {
await User.resetPassword(this.id, newPassword);
this.password = newPassword;
} | /**
* Reset this users password
* @param {string} newPassword
* @returns {Promise<void>}
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/models/user.ts#L26-L29 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | User.createJWT | static createJWT(user : User, jwtSecret : string) {
return jwt.sign({
username: user.username,
h: shake256(user.password, SHAKE256_LENGTH),
}, jwtSecret);
} | /**
* Create a new JWT for a user
* @param {User} user The User to create a JsonWebToken for
* @param {string} jwtSecret The key used to sign the JsonWebToken
* @returns {string} the JsonWebToken as a string
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/backend/models/user.ts#L37-L42 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | copyYAMLCommentsItems | function copyYAMLCommentsItems(items: any, srcItems: any) {
if (!items || !srcItems) {
return;
}
// First pass - try to match items by their content
for (let i = 0; i < items.length; i++) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const item: any = items[i]... | /**
* Copy yaml comments from srcItems to items
* Attempts to preserve comments by matching content rather than just array indices
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/common/util-common.ts#L242-L300 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | traverseYAML | function traverseYAML(pair : Pair, env : DotenvParseOutput) : void {
// @ts-ignore
if (pair.value && pair.value.items) {
// @ts-ignore
for (const item of pair.value.items) {
if (item instanceof Pair) {
traverseYAML(item, env);
} else if (item instanceof Sc... | /**
* Used for envsubstYAML(...)
* @param pair
* @param env
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/common/util-common.ts#L409-L429 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | question | function question(question : string) : Promise<string> {
return new Promise((resolve) => {
rl.question(question, (answer) => {
resolve(answer);
});
});
} | /**
* Ask question of user
* @param question Question to ask
* @returns Users response
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/extra/reset-password.ts#L79-L85 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | commit | function commit(version) {
let msg = "Update to " + version;
let res = childProcess.spawnSync("git", [ "commit", "-m", msg, "-a" ]);
let stdout = res.stdout.toString().trim();
console.log(stdout);
if (stdout.includes("no changes added to commit")) {
throw new Error("commit error");
}
} | /**
* Commit updated files
* @param {string} version Version to update to
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/extra/update-version.ts#L30-L40 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | tag | function tag(version) {
let res = childProcess.spawnSync("git", [ "tag", version ]);
console.log(res.stdout.toString().trim());
} | /**
* Create a tag with the specified version
* @param {string} version Tag to create
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/extra/update-version.ts#L46-L49 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | tagExists | function tagExists(version) {
if (! version) {
throw new Error("invalid version");
}
let res = childProcess.spawnSync("git", [ "tag", "-l", version ]);
return res.stdout.toString().trim() === version;
} | /**
* Check if a tag exists for the specified version
* @param {string} version Version to check
* @returns {boolean} Does the tag already exist
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/extra/update-version.ts#L56-L64 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | rootApp | function rootApp() {
const toast = useToast();
return defineComponent({
mixins: [
socket,
lang,
theme,
],
data() {
return {
loggedIn: false,
allowLoginDialog: false,
username: null,
... | /**
* Root Vue component
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/frontend/src/main.ts#L43-L105 | d451e06e8428f1bf987595bf51d65f82241294cd |
dockge | github_2023 | louislam | typescript | getTimezoneOffset | function getTimezoneOffset(timeZone : string) {
const now = new Date();
const tzString = now.toLocaleString("en-US", {
timeZone,
});
const localString = now.toLocaleString("en-US");
const diff = (Date.parse(localString) - Date.parse(tzString)) / 3600000;
const offset = diff + now.getTime... | /**
* Returns the offset from UTC in hours for the current locale.
* @param {string} timeZone Timezone to get offset for
* @returns {number} The offset from UTC in hours.
*
* Generated by Trelent
*/ | https://github.com/louislam/dockge/blob/d451e06e8428f1bf987595bf51d65f82241294cd/frontend/src/util-frontend.ts#L13-L22 | d451e06e8428f1bf987595bf51d65f82241294cd |
maxun | github_2023 | getmaxun | typescript | Interpreter.getSelectors | private getSelectors(workflow: Workflow): string[] {
const selectorsSet = new Set<string>();
if (workflow.length === 0) {
return [];
}
for (let index = workflow.length - 1; index >= 0; index--) {
const currentSelectors = workflow[index]?.where?.selectors;
if (currentSelectors ... | // } | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/interpret.ts#L159-L176 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | Interpreter.getState | private async getState(page: Page, workflowCopy: Workflow, selectors: string[]): Promise<PageState> {
/**
* All the selectors present in the current Workflow
*/
// const selectors = Preprocessor.extractSelectors(workflow);
// console.log("Current selectors:", selectors);
/**
* Determine... | /**
* Returns the context object from given Page and the current workflow.\
* \
* `workflow` is used for selector extraction - function searches for used selectors to
* look for later in the page's context.
* @param page Playwright Page object
* @param workflow Current **initialized** workflow (... | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/interpret.ts#L188-L257 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | Interpreter.applicable | private applicable(where: Where, context: PageState, usedActions: string[] = []): boolean {
/**
* Given two arbitrary objects, determines whether `subset` is a subset of `superset`.\
* \
* For every key in `subset`, there must be a corresponding key with equal scalar
* value in `superset`, or `i... | /**
* Tests if the given action is applicable with the given context.
* @param where Tested *where* condition
* @param context Current browser context.
* @returns True if `where` is applicable in the given context, false otherwise
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/interpret.ts#L265-L346 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | inclusive | const inclusive = (subset: Record<string, unknown>, superset: Record<string, unknown>)
: boolean => (
Object.entries(subset).every(
([key, value]) => {
/**
* Arrays are compared without order (are transformed into objects before comparison).
*/
const parsedV... | /**
* Given two arbitrary objects, determines whether `subset` is a subset of `superset`.\
* \
* For every key in `subset`, there must be a corresponding key with equal scalar
* value in `superset`, or `inclusive(subset[key], superset[key])` must hold.
* @param subset Arbitrary non-cyclic JS ob... | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/interpret.ts#L275-L302 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | Interpreter.carryOutSteps | private async carryOutSteps(page: Page, steps: What[]): Promise<void> {
/**
* Defines overloaded (or added) methods/actions usable in the workflow.
* If a method overloads any existing method of the Page class, it accepts the same set
* of parameters *(but can override some!)*\
* \
* Also, ... | /**
* Given a Playwright's page object and a "declarative" list of actions, this function
* calls all mentioned functions on the Page object.\
* \
* Manipulates the iterator indexes (experimental feature, likely to be removed in
* the following versions of maxun-core)
* @param page Playwright Page object
* @para... | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/interpret.ts#L357-L549 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | debugLog | const debugLog = (message: string, ...args: any[]) => {
console.log(`[Page ${visitedUrls.size}] [URL: ${page.url()}] ${message}`, ...args);
}; | // 1 second delay between retries | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/interpret.ts#L564-L566 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | findWorkingButton | const findWorkingButton = async (selectors: string[], retryCount = 0): Promise<{
button: ElementHandle | null,
workingSelector: string | null
}> => {
for (const selector of selectors) {
try {
const button = await page.waitForSelector(selector, {
state: 'attache... | // Enhanced button finder with retry mechanism | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/interpret.ts#L589-L616 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | Interpreter.run | public async run(page: Page, params?: ParamType): Promise<void> {
this.log('Starting the workflow.', Level.LOG);
const context = page.context();
page.setDefaultNavigationTimeout(100000);
// Check proxy settings from context options
const contextOptions = (context as any)._options;
const ha... | /**
* Spawns a browser context and runs given workflow.
* \
* Resolves after the playback is finished.
* @param {Page} [page] Page to run the workflow on.
* @param {ParamType} params Workflow specific, set of parameters
* for the `{$param: nameofparam}` fields.
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/interpret.ts#L1034-L1070 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | Preprocessor.getParams | static getParams(workflow: WorkflowFile): string[] {
const getParamsRecurse = (object: any): string[] => {
if (typeof object === 'object') {
// Recursion base case
if (object.$param) {
return [object.$param];
}
// Recursion general case
return (Object.values(... | /**
* Extracts parameter names from the workflow.
* @param {WorkflowFile} workflow The given workflow
* @returns {String[]} List of parameters' names.
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/preprocessor.ts#L54-L70 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | Preprocessor.extractSelectors | static extractSelectors(workflow: Workflow): SelectorArray {
/**
* Given a Where condition, this function extracts
* all the existing selectors from it (recursively).
*/
const selectorsFromCondition = (where: Where): SelectorArray => {
// the `selectors` field is either on the top level
let out = wh... | // TODO : add recursive selector search (also in click/fill etc. events?) | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/preprocessor.ts#L77-L108 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | selectorsFromCondition | const selectorsFromCondition = (where: Where): SelectorArray => {
// the `selectors` field is either on the top level
let out = where.selectors ?? [];
if (!Array.isArray(out)) {
out = [out];
}
// or nested in the "operator" array
operators.forEach((op) => {
let condW... | /**
* Given a Where condition, this function extracts
* all the existing selectors from it (recursively).
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/preprocessor.ts#L82-L101 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | Preprocessor.initWorkflow | static initWorkflow(workflow: Workflow, params?: ParamType): Workflow {
const paramNames = this.getParams({ workflow });
if (Object.keys(params ?? {}).sort().join(',') !== paramNames.sort().join(',')) {
throw new Error(`Provided parameters do not match the workflow parameters
provided: ${Object.key... | /**
* Recursively crawl `object` and initializes params - replaces the `{$param : paramName}` objects
* with the defined value.
* @returns {Workflow} Copy of the given workflow, modified (the initial workflow is left untouched).
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/preprocessor.ts#L115-L178 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | initSpecialRecurse | const initSpecialRecurse = (
object: unknown,
k: string,
f: (value: string) => unknown,
): unknown => {
if (!object || typeof object !== 'object') {
return object;
}
const out = object;
// for every key (child) of the object
Object.keys(object!).forEach((key)... | /**
* A recursive method for initializing special `{key: value}` syntax objects in the workflow.
* @param object Workflow to initialize (or a part of it).
* @param k key to look for ($regex, $param)
* @param f function mutating the special `{}` syntax into
* its true representation (... | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/preprocessor.ts#L132-L153 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | Concurrency.constructor | constructor(maxConcurrency: number) {
this.maxConcurrency = maxConcurrency;
} | /**
* Constructs a new instance of concurrency manager.
* @param {number} maxConcurrency Maximum number of workers running in parallel.
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/utils/concurrency.ts#L29-L31 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | Concurrency.runNextJob | private runNextJob(): void {
const job = this.jobQueue.pop();
if (job) {
// console.debug("Running a job...");
job().then(() => {
// console.debug("Job finished, running the next waiting job...");
this.runNextJob();
});
} else {
// console.debug("No waiting job found... | /**
* Takes a waiting job out of the queue and runs it.
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/utils/concurrency.ts#L36-L53 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | Concurrency.addJob | addJob(job: () => Promise<any>): void {
// console.debug("Adding a worker!");
this.jobQueue.push(job);
if (!this.maxConcurrency || this.activeWorkers < this.maxConcurrency) {
this.runNextJob();
this.activeWorkers += 1;
} else {
// console.debug("No capacity to run a worker now, waitin... | /**
* Pass a job (a time-demanding async function) to the concurrency manager. \
* The time of the job's execution depends on the concurrency manager itself
* (given a generous enough `maxConcurrency` value, it might be immediate,
* but this is not guaranteed).
* @param worker Async function to be executed (j... | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/utils/concurrency.ts#L62-L72 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | Concurrency.waitForCompletion | waitForCompletion(): Promise<void> {
return new Promise((res) => {
this.waiting.push(res);
});
} | /**
* Waits until there is no running nor waiting job. \
* If the concurrency manager is idle at the time of calling this function,
* it waits until at least one job is completed (can be "presubscribed").
* @returns Promise, resolved after there is no running/waiting worker.
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/maxun-core/src/utils/concurrency.ts#L80-L84 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | measureFPS | const measureFPS = () => {
const currentTime = performance.now();
const elapsed = currentTime - this.lastFrameTime;
this.frameCount++;
if (elapsed >= 1000) { // Calculate FPS every second
const fps = Math.round((this.frameCount * 1000) / elapsed);
... | // Monitor FPS | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/perf/performance.ts#L28-L40 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | FrontendPerformanceMonitor.measureRenderTime | public measureRenderTime(renderFunction: () => void): void {
const startTime = performance.now();
renderFunction();
const endTime = performance.now();
this.metrics.renderTime.push(endTime - startTime);
} | // Monitor Canvas Render Time | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/perf/performance.ts#L57-L62 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | FrontendPerformanceMonitor.measureEventLatency | public measureEventLatency(event: MouseEvent | KeyboardEvent): void {
const latency = performance.now() - event.timeStamp;
this.metrics.eventLatency.push(latency);
} | // Monitor Event Latency | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/perf/performance.ts#L65-L68 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | FrontendPerformanceMonitor.getPerformanceReport | public getPerformanceReport(): PerformanceReport {
return {
averageFPS: this.calculateAverage(this.metrics.fps),
averageRenderTime: this.calculateAverage(this.metrics.renderTime),
averageEventLatency: this.calculateAverage(this.metrics.eventLatency),
memoryTrend: ... | // Get Performance Report | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/perf/performance.ts#L71-L79 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | handleWrapper | const handleWrapper = async (
handleCallback: (
generator: WorkflowGenerator,
page: Page,
args?: any
) => Promise<void>,
args?: any
) => {
const id = browserPool.getActiveBrowserId();
if (id) {
const activeBrowser = browserPool.getRemoteBrowser(id);
if (active... | /**
* A wrapper function for handling user input.
* This function gets the active browser instance from the browser pool
* and passes necessary arguments to the appropriate handlers.
* e.g. {@link Generator}, {@link RemoteBrowser.currentPage}
*
* Also ignores any user input while interpretation is in progress.
*... | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L28-L56 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | onGenerateAction | const onGenerateAction = async (customActionEventData: CustomActionEventData) => {
logger.log('debug', `Generating ${customActionEventData.action} action emitted from client`);
await handleWrapper(handleGenerateAction, customActionEventData);
} | /**
* A wrapper function for handling custom actions.
* @param customActionEventData The custom action event data
* @category HelperFunctions
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L72-L75 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | handleGenerateAction | const handleGenerateAction =
async (generator: WorkflowGenerator, page: Page, { action, settings }: CustomActionEventData) => {
await generator.customAction(action, settings, page);
} | /**
* Handles the generation of a custom action workflow pair.
* @param generator The workflow generator
* @param page The active page
* @param action The custom action
* @param settings The custom action settings
* @category BrowserManagement
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L85-L88 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | onMousedown | const onMousedown = async (coordinates: Coordinates) => {
logger.log('debug', 'Handling mousedown event emitted from client');
await handleWrapper(handleMousedown, coordinates);
} | /**
* A wrapper function for handling mousedown event.
* @param coordinates - coordinates of the mouse click
* @category HelperFunctions
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L95-L98 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | handleMousedown | const handleMousedown = async (generator: WorkflowGenerator, page: Page, { x, y }: Coordinates) => {
await generator.onClick({ x, y }, page);
const previousUrl = page.url();
const tabsBeforeClick = page.context().pages().length;
await page.mouse.click(x, y);
// try if the click caused a navigation t... | /**
* A mousedown event handler.
* Reproduces the click on the remote browser instance
* and generates pair data for the recorded workflow.
* @param generator - the workflow generator {@link Generator}
* @param page - the active page of the remote browser
* @param x - the x coordinate of the mousedown event
* @p... | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L110-L138 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | onWheel | const onWheel = async (scrollDeltas: ScrollDeltas) => {
logger.log('debug', 'Handling scroll event emitted from client');
await handleWrapper(handleWheel, scrollDeltas);
}; | /**
* A wrapper function for handling the wheel event.
* @param scrollDeltas - the scroll deltas of the wheel event
* @category HelperFunctions
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L145-L148 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | handleWheel | const handleWheel = async (generator: WorkflowGenerator, page: Page, { deltaX, deltaY }: ScrollDeltas) => {
await page.mouse.wheel(deltaX, deltaY);
logger.log('debug', `Scrolled horizontally ${deltaX} pixels and vertically ${deltaY} pixels`);
}; | /**
* A wheel event handler.
* Reproduces the wheel event on the remote browser instance.
* Scroll is not generated for the workflow pair. This is because
* Playwright scrolls elements into focus on any action.
* @param generator - the workflow generator {@link Generator}
* @param page - the active page of the re... | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L161-L164 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | onMousemove | const onMousemove = async (coordinates: Coordinates) => {
logger.log('debug', 'Handling mousemove event emitted from client');
await handleWrapper(handleMousemove, coordinates);
} | /**
* A wrapper function for handling the mousemove event.
* @param coordinates - the coordinates of the mousemove event
* @category HelperFunctions
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L171-L174 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | handleMousemove | const handleMousemove = async (generator: WorkflowGenerator, page: Page, { x, y }: Coordinates) => {
try {
await page.mouse.move(x, y);
throttle(async () => {
await generator.generateDataForHighlighter(page, { x, y });
}, 100)();
logger.log('debug', `Moved over position x... | /**
* A mousemove event handler.
* Reproduces the mousemove event on the remote browser instance
* and generates data for the client's highlighter.
* Mousemove is also not reflected in the workflow.
* @param generator - the workflow generator {@link Generator}
* @param page - the active page of the remote browser... | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L187-L198 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | onKeydown | const onKeydown = async (keyboardInput: KeyboardInput) => {
logger.log('debug', 'Handling keydown event emitted from client');
await handleWrapper(handleKeydown, keyboardInput);
} | /**
* A wrapper function for handling the keydown event.
* @param keyboardInput - the keyboard input of the keydown event
* @category HelperFunctions
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L205-L208 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | handleKeydown | const handleKeydown = async (generator: WorkflowGenerator, page: Page, { key, coordinates }: KeyboardInput) => {
await page.keyboard.down(key);
await generator.onKeyboardInput(key, coordinates, page);
logger.log('debug', `Key ${key} pressed`);
}; | /**
* A keydown event handler.
* Reproduces the keydown event on the remote browser instance
* and generates the workflow pair data.
* @param generator - the workflow generator {@link Generator}
* @param page - the active page of the remote browser
* @param key - the pressed key
* @param coordinates - the coordi... | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L220-L224 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | handleDateSelection | const handleDateSelection = async (generator: WorkflowGenerator, page: Page, data: DatePickerEventData) => {
await generator.onDateSelection(page, data);
logger.log('debug', `Date ${data.value} selected`);
} | /**
* Handles the date selection event.
* @param generator - the workflow generator {@link Generator}
* @param page - the active page of the remote browser
* @param data - the data of the date selection event {@link DatePickerEventData}
* @category BrowserManagement
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L233-L236 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | onKeyup | const onKeyup = async (keyboardInput: KeyboardInput) => {
logger.log('debug', 'Handling keyup event emitted from client');
await handleWrapper(handleKeyup, keyboardInput);
} | /**
* A wrapper function for handling the keyup event.
* @param keyboardInput - the keyboard input of the keyup event
* @category HelperFunctions
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L278-L281 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | handleKeyup | const handleKeyup = async (generator: WorkflowGenerator, page: Page, key: string) => {
await page.keyboard.up(key);
logger.log('debug', `Key ${key} unpressed`);
}; | /**
* A keyup event handler.
* Reproduces the keyup event on the remote browser instance.
* Does not generate any data - keyup is not reflected in the workflow.
* @param generator - the workflow generator {@link Generator}
* @param page - the active page of the remote browser
* @param key - the released key
* @c... | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L292-L295 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | onChangeUrl | const onChangeUrl = async (url: string) => {
logger.log('debug', 'Handling change url event emitted from client');
await handleWrapper(handleChangeUrl, url);
} | /**
* A wrapper function for handling the url change event.
* @param url - the new url of the page
* @category HelperFunctions
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L302-L305 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | handleChangeUrl | const handleChangeUrl = async (generator: WorkflowGenerator, page: Page, url: string) => {
if (url) {
await generator.onChangeUrl(url, page);
try {
await page.goto(url);
logger.log('debug', `Went to ${url}`);
} catch (e) {
const { message } = e as Error;
... | /**
* An url change event handler.
* Navigates the page to the given url and generates data for the workflow.
* @param generator - the workflow generator {@link Generator}
* @param page - the active page of the remote browser
* @param url - the new url of the page
* @category BrowserManagement
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L315-L328 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | onRefresh | const onRefresh = async () => {
logger.log('debug', 'Handling refresh event emitted from client');
await handleWrapper(handleRefresh);
} | /**
* A wrapper function for handling the refresh event.
* @category HelperFunctions
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L334-L337 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | handleRefresh | const handleRefresh = async (generator: WorkflowGenerator, page: Page) => {
await page.reload();
logger.log('debug', `Page refreshed.`);
}; | /**
* A refresh event handler.
* Refreshes the page. This is not reflected in the workflow.
* @param generator - the workflow generator {@link Generator}
* @param page - the active page of the remote browser
* @category BrowserManagement
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L346-L349 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | onGoBack | const onGoBack = async () => {
logger.log('debug', 'Handling refresh event emitted from client');
await handleWrapper(handleGoBack);
} | /**
* A wrapper function for handling the go back event.
* @category HelperFunctions
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L355-L358 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | handleGoBack | const handleGoBack = async (generator: WorkflowGenerator, page: Page) => {
await page.goBack({ waitUntil: 'commit' });
generator.onGoBack(page.url());
logger.log('debug', 'Page went back')
}; | /**
* A go back event handler.
* Navigates the page back and generates data for the workflow.
* @param generator - the workflow generator {@link Generator}
* @param page - the active page of the remote browser
* @category BrowserManagement
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L367-L371 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | onGoForward | const onGoForward = async () => {
logger.log('debug', 'Handling refresh event emitted from client');
await handleWrapper(handleGoForward);
} | /**
* A wrapper function for handling the go forward event.
* @category HelperFunctions
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L377-L380 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | handleGoForward | const handleGoForward = async (generator: WorkflowGenerator, page: Page) => {
await page.goForward({ waitUntil: 'commit' });
generator.onGoForward(page.url());
logger.log('debug', 'Page went forward');
}; | /**
* A go forward event handler.
* Navigates the page forward and generates data for the workflow.
* @param generator - the workflow generator {@link Generator}
* @param page - the active page of the remote browser
* @category BrowserManagement
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L389-L393 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | registerInputHandlers | const registerInputHandlers = (socket: Socket) => {
socket.on("input:mousedown", onMousedown);
socket.on("input:wheel", onWheel);
socket.on("input:mousemove", onMousemove);
socket.on("input:keydown", onKeydown);
socket.on("input:keyup", onKeyup);
socket.on("input:url", onChangeUrl);
socket.o... | /**
* Helper function for registering the handlers onto established websocket connection.
* Registers:
* - mousedownHandler
* - wheelHandler
* - mousemoveHandler
* - keydownHandler
* - keyupHandler
* - changeUrlHandler
* - refreshHandler
* - goBackHandler
* - goForwardHandler
* - onGenerateAction
* input h... | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/inputHandlers.ts#L418-L433 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | BrowserPool.deleteRemoteBrowser | public addRemoteBrowser = (id: string, browser: RemoteBrowser, active: boolean = false): void => {
this.pool = {
...this.pool,
[id]: {
browser,
active,
},
}
logger.log('debug', `Remote browser with id: ${id} added to the pool`);... | /**
* Returns the active browser's instance id from the pool.
* If there is no active browser, it returns undefined.
* If there are multiple active browsers, it returns the first one.
* @returns the first remote active browser instance's id from the pool
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/classes/BrowserPool.ts | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | RemoteBrowser.constructor | public constructor(socket: Socket) {
this.socket = socket;
this.interpreter = new WorkflowInterpreter(socket);
this.generator = new WorkflowGenerator(socket);
} | /**
* Initializes a new instances of the {@link Generator} and {@link WorkflowInterpreter} classes and
* assigns the socket instance everywhere.
* @param socket socket.io socket instance used to communicate with the client side
* @constructor
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/classes/RemoteBrowser.ts#L116-L120 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | RemoteBrowser.normalizeUrl | private normalizeUrl(url: string): string {
try {
const parsedUrl = new URL(url);
// Remove trailing slashes except for root path
parsedUrl.pathname = parsedUrl.pathname.replace(/\/+$/, '') || '/';
// Ensure consistent protocol handling
parsedUrl.proto... | /**
* Normalizes URLs to prevent navigation loops while maintaining consistent format
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/classes/RemoteBrowser.ts#L165-L176 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | RemoteBrowser.shouldEmitUrlChange | private shouldEmitUrlChange(newUrl: string): boolean {
if (!this.lastEmittedUrl) {
return true;
}
const normalizedNew = this.normalizeUrl(newUrl);
const normalizedLast = this.normalizeUrl(this.lastEmittedUrl);
return normalizedNew !== normalizedLast;
} | /**
* Determines if a URL change is significant enough to emit
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/classes/RemoteBrowser.ts#L181-L188 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | RemoteBrowser.interpretCurrentRecording | public initialize = async (userId: string): Promise<void> => {
this.browser = <Browser>(await chromium.launch({
headless: true,
args: [
"--disable-blink-features=AutomationControlled",
"--disable-web-security",
"--disable-features=IsolateOr... | /**
* Subscribes the remote browser for a screencast session
* on [CDP](https://chromedevtools.github.io/devtools-protocol/) level,
* where screenshot is being sent through the socket
* every time the browser's active page updates.
* @returns {Promise<void>}
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/classes/RemoteBrowser.ts | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | RemoteBrowser.registerEditorEvents | public registerEditorEvents = (): void => {
this.socket.on('rerender', async () => await this.makeAndEmitScreenshot());
this.socket.on('settings', (settings) => this.interpreterSettings = settings);
this.socket.on('changeTab', async (tabIndex) => await this.changeTab(tabIndex));
this.soc... | /**
* Registers all event listeners needed for the recording editor session.
* Should be called only once after the full initialization of the remote browser.
* @returns void
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/classes/RemoteBrowser.ts#L335-L375 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | RemoteBrowser.switchOff | public async switchOff(): Promise<void> {
try {
await this.interpreter.stopInterpretation();
if (this.screencastInterval) {
clearInterval(this.screencastInterval);
}
if (this.client) {
await this.stopScreencast();
}
... | /**
* Terminates the screencast session and closes the remote browser.
* If an interpretation was running it will be stopped.
* @returns {Promise<void>}
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/classes/RemoteBrowser.ts#L411-L433 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | RemoteBrowser.changeTab | private changeTab = async (tabIndex: number): Promise<void> => {
const page = this.currentPage?.context().pages()[tabIndex];
if (page) {
await this.stopScreencast();
this.currentPage = page;
await this.setupPageEventListeners(this.currentPage);
//await t... | /**
* Changes the active page to the page instance on the given index
* available in pages array on the {@link BrowserContext}.
* Automatically stops the screencast session on the previous page and starts the new one.
* @param tabIndex index of the page in the pages array on the {@link BrowserContex... | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/classes/RemoteBrowser.ts#L546-L562 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | RemoteBrowser.startScreencast | private async startScreencast(): Promise<void> {
if (!this.client) {
logger.warn('Client is not initialized');
return;
}
try {
await this.client.send('Page.startScreencast', {
format: SCREENCAST_CONFIG.format,
});
// S... | /**
* Initiates screencast of the remote browser through socket,
* registers listener for rerender event and emits the loaded event.
* Should be called only once after the browser is fully initialized.
* @returns {Promise<void>}
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/browser-management/classes/RemoteBrowser.ts#L595-L621 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | BinaryOutputService.uploadAndStoreBinaryOutput | async uploadAndStoreBinaryOutput(run: Run, binaryOutput: Record<string, any>): Promise<Record<string, string>> {
const uploadedBinaryOutput: Record<string, string> = {};
const plainRun = run.toJSON();
for (const key of Object.keys(binaryOutput)) {
let binaryData = binaryOutput[key];
if (!plain... | /**
* Uploads binary data to Minio and stores references in PostgreSQL.
* @param run - The run object representing the current process.
* @param binaryOutput - The binary output object containing data to upload.
* @returns A map of Minio URLs pointing to the uploaded binary data.
*/ | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/storage/mino.ts#L70-L132 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | traverseShadowDOM | const traverseShadowDOM = (element: HTMLElement): HTMLElement => {
let current = element;
let shadowRoot = current.shadowRoot;
let deepest = current;
while (shadowRoot) {
const shadowElement = shadowRoot.elementFromPoint(x, y) as HTMLElement;
... | // Function to traverse shadow DOM | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/workflow-management/selector.ts#L35-L50 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | getDeepestElementFromPoint | const getDeepestElementFromPoint = (x: number, y: number): HTMLElement | null => {
// First, get the element at the clicked coordinates in the main document
let element = document.elementFromPoint(x, y) as HTMLElement;
if (!element) return null;
// Track the deepest elem... | // Enhanced helper function to get element from point including shadow DOM | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/workflow-management/selector.ts#L26-L89 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | traverseShadowDOM | const traverseShadowDOM = (element: HTMLElement, depth: number = 0): HTMLElement => {
const MAX_SHADOW_DEPTH = 4;
let current = element;
let deepest = current;
while (current && depth < MAX_SHADOW_DEPTH) {
const shadowRoot = current.shadowRoot;
if (!shado... | // Helper function to traverse shadow DOM | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/workflow-management/selector.ts#L1205-L1223 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | getIframePath | const getIframePath = (el: HTMLElement) => {
const path = [];
let current = el;
let depth = 0;
const MAX_DEPTH = 4;
while (current && depth < MAX_DEPTH) {
// Get the owner document of the current element
const owner... | // Helper function to get the complete iframe path up to document root | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/workflow-management/selector.ts#L1279-L1306 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
maxun | github_2023 | getmaxun | typescript | genSelectorForShadowDOM | const genSelectorForShadowDOM = (element: HTMLElement) => {
// Get complete path up to document root
const getShadowPath = (el: HTMLElement) => {
const path = [];
let current = el;
let depth = 0;
const MAX_DEPTH = 4;
while (current && depth < ... | // Helper function to generate selectors for shadow DOM elements | https://github.com/getmaxun/maxun/blob/be7c599195a0e2a1c08a28a9eb094a79359a3e9c/server/src/workflow-management/selector.ts#L1344-L1401 | be7c599195a0e2a1c08a28a9eb094a79359a3e9c |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.