Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion server/src/workflow-management/classes/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ export class WorkflowGenerator {
}

if ((elementInfo?.tagName === 'INPUT' || elementInfo?.tagName === 'TEXTAREA') && selector) {
if (page.isClosed()) {
logger.log('debug', 'Page is closed, cannot get cursor position');
return;
}
const positionAndCursor = await page.evaluate(
({ selector, coords }) => {
const getCursorPosition = (element: any, clickX: any) => {
Expand Down Expand Up @@ -1342,4 +1346,4 @@ export class WorkflowGenerator {
public clearLastIndex = () => {
this.generatedData.lastIndex = null;
}
}
}
32 changes: 32 additions & 0 deletions server/src/workflow-management/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export const getElementInformation = async (
) => {
try {
if (!getList || listSelector !== '') {
if (page.isClosed()) {
logger.debug('Page is closed, cannot get element information');
return null;
}
const elementInfo = await page.evaluate(
async ({ x, y }) => {
const getDeepestElementFromPoint = (x: number, y: number): HTMLElement | null => {
Expand Down Expand Up @@ -302,6 +306,10 @@ export const getElementInformation = async (
);
return elementInfo;
} else {
if (page.isClosed()) {
logger.debug('Page is closed, cannot get element information (else branch)');
return null;
}
const elementInfo = await page.evaluate(
async ({ x, y }) => {
const getDeepestElementFromPoint = (x: number, y: number): HTMLElement | null => {
Expand Down Expand Up @@ -611,6 +619,10 @@ export const getElementInformation = async (
export const getRect = async (page: Page, coordinates: Coordinates, listSelector: string, getList: boolean) => {
try {
if (!getList || listSelector !== '') {
if (page.isClosed()) {
logger.debug('Page is closed, cannot get element rect');
return null;
}
const rect = await page.evaluate(
async ({ x, y }) => {
const getDeepestElementFromPoint = (x: number, y: number): HTMLElement | null => {
Expand Down Expand Up @@ -834,6 +846,10 @@ export const getRect = async (page: Page, coordinates: Coordinates, listSelector
);
return rect;
} else {
if (page.isClosed()) {
logger.debug('Page is closed, cannot get element rect (else branch)');
return null;
}
const rect = await page.evaluate(
async ({ x, y }) => {
const getDeepestElementFromPoint = (x: number, y: number): HTMLElement | null => {
Expand Down Expand Up @@ -1076,6 +1092,10 @@ export const getRect = async (page: Page, coordinates: Coordinates, listSelector
*/
export const getSelectors = async (page: Page, coordinates: Coordinates) => {
try {
if (page.isClosed()) {
logger.debug('Page is closed, cannot get selectors');
return null;
}
const selectors: any = await page.evaluate(async ({ x, y }) => {
// version @medv/finder
// https://github.com/antonmedv/finder/blob/master/finder.ts
Expand Down Expand Up @@ -2010,6 +2030,10 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates

try {
if (!listSelector) {
if (page.isClosed()) {
logger.debug('Page is closed, cannot get non-unique selectors');
return { generalSelector: '' };
}
const selectors = await page.evaluate(({ x, y }: { x: number, y: number }) => {
const getDeepestElementFromPoint = (x: number, y: number): HTMLElement | null => {
let elements = document.elementsFromPoint(x, y) as HTMLElement[];
Expand Down Expand Up @@ -2364,6 +2388,10 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates
return selectors || { generalSelector: '' };
} else {
// When we have a list selector, we need special handling while maintaining shadow DOM and frame support
if (page.isClosed()) {
logger.debug('Page is closed, cannot get list selectors');
return { generalSelector: '' };
}
const selectors = await page.evaluate(({ x, y }: { x: number, y: number }) => {
const getDeepestElementFromPoint = (x: number, y: number): HTMLElement | null => {
let elements = document.elementsFromPoint(x, y) as HTMLElement[];
Expand Down Expand Up @@ -2725,6 +2753,10 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates

export const getChildSelectors = async (page: Page, parentSelector: string): Promise<string[]> => {
try {
if (page.isClosed()) {
logger.debug('Page is closed, cannot get child selectors');
return [];
}
const childSelectors = await page.evaluate((parentSelector: string) => {
// Function to get a non-unique selector based on tag and class (if present)
function getNonUniqueSelector(element: HTMLElement): string {
Expand Down