pull:初次提交
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as close from './close.operation';
|
||||
import * as create from './create.operation';
|
||||
import * as getLiveView from './getLiveView.operation';
|
||||
import * as list from './list.operation';
|
||||
import * as load from './load.operation';
|
||||
import * as takeScreenshot from './takeScreenshot.operation';
|
||||
import { sessionIdField, windowIdField } from '../common/fields';
|
||||
|
||||
export { create, close, takeScreenshot, load, list, getLiveView };
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
typeOptions: {
|
||||
sortable: false,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['window'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Close Window',
|
||||
value: 'close',
|
||||
description: 'Close a window inside a session',
|
||||
action: 'Close a window',
|
||||
},
|
||||
{
|
||||
name: 'Create a New Browser Window',
|
||||
value: 'create',
|
||||
description: 'Create a new browser window inside a session. Can load a URL when created.',
|
||||
action: 'Create a window',
|
||||
},
|
||||
{
|
||||
name: 'Get Live View',
|
||||
value: 'getLiveView',
|
||||
description: 'Get information about a browser window, including the live view URL',
|
||||
action: 'Get live view',
|
||||
},
|
||||
{
|
||||
name: 'List Windows',
|
||||
value: 'list',
|
||||
description: 'List all browser windows in a session',
|
||||
action: 'List windows',
|
||||
},
|
||||
{
|
||||
name: 'Load URL',
|
||||
value: 'load',
|
||||
description: 'Load a URL in an existing window',
|
||||
action: 'Load a page',
|
||||
},
|
||||
{
|
||||
name: 'Take Screenshot',
|
||||
value: 'takeScreenshot',
|
||||
description: 'Take a screenshot of the current window',
|
||||
action: 'Take screenshot',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
{
|
||||
...sessionIdField,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['window'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
...windowIdField,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['window'],
|
||||
operation: ['close', 'takeScreenshot', 'load', 'getLiveView'],
|
||||
},
|
||||
},
|
||||
},
|
||||
...create.description,
|
||||
...list.description,
|
||||
...getLiveView.description,
|
||||
...load.description,
|
||||
...takeScreenshot.description,
|
||||
];
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
||||
|
||||
import { validateAirtopApiResponse, validateSessionAndWindowId } from '../../GenericFunctions';
|
||||
import { apiRequest } from '../../transport';
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const { sessionId, windowId } = validateSessionAndWindowId.call(this, index);
|
||||
|
||||
const response = await apiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/sessions/${sessionId}/windows/${windowId}`,
|
||||
);
|
||||
|
||||
// validate response
|
||||
validateAirtopApiResponse(this.getNode(), response);
|
||||
|
||||
return this.helpers.returnJsonArray({ sessionId, windowId, ...response });
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
IDataObject,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
validateAirtopApiResponse,
|
||||
validateSessionId,
|
||||
validateUrl,
|
||||
validateScreenResolution,
|
||||
} from '../../GenericFunctions';
|
||||
import { apiRequest } from '../../transport';
|
||||
import type { IAirtopResponse } from '../../transport/types';
|
||||
import { urlField } from '../common/fields';
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
...urlField,
|
||||
description: 'Initial URL to load in the window. Defaults to https://www.google.com.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['window'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
// Live View Options
|
||||
{
|
||||
displayName: 'Get Live View',
|
||||
name: 'getLiveView',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Whether to get the URL of the window\'s <a href="https://docs.airtop.ai/guides/how-to/creating-a-live-view" target="_blank">Live View</a>',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['window'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Include Navigation Bar',
|
||||
name: 'includeNavigationBar',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Whether to include the navigation bar in the Live View. When enabled, the navigation bar will be visible allowing you to navigate between pages.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['window'],
|
||||
operation: ['create'],
|
||||
getLiveView: [true],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Screen Resolution',
|
||||
name: 'screenResolution',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'The screen resolution of the Live View. Setting a resolution will force the window to open at that specific size.',
|
||||
placeholder: 'e.g. 1280x720',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['window'],
|
||||
operation: ['create'],
|
||||
getLiveView: [true],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Disable Resize',
|
||||
name: 'disableResize',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to disable the window from being resized in the Live View',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['window'],
|
||||
operation: ['create'],
|
||||
getLiveView: [true],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['window'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Wait Until',
|
||||
name: 'waitUntil',
|
||||
type: 'options',
|
||||
description: 'Wait until the specified loading event occurs',
|
||||
default: 'load',
|
||||
options: [
|
||||
{
|
||||
name: 'Load',
|
||||
value: 'load',
|
||||
description: 'Wait until the page dom and its assets have loaded',
|
||||
},
|
||||
{
|
||||
name: 'DOM Content Loaded',
|
||||
value: 'domContentLoaded',
|
||||
description: 'Wait until the page DOM has loaded',
|
||||
},
|
||||
{
|
||||
name: 'Complete',
|
||||
value: 'complete',
|
||||
description: 'Wait until all iframes in the page have loaded',
|
||||
},
|
||||
{
|
||||
name: 'No Wait',
|
||||
value: 'noWait',
|
||||
description: 'Do not wait for any loading event and it will return immediately',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const sessionId = validateSessionId.call(this, index);
|
||||
const url = validateUrl.call(this, index);
|
||||
const additionalFields = this.getNodeParameter('additionalFields', index);
|
||||
// Live View Options
|
||||
const getLiveView = this.getNodeParameter('getLiveView', index, false);
|
||||
const includeNavigationBar = this.getNodeParameter('includeNavigationBar', index, false);
|
||||
const screenResolution = validateScreenResolution.call(this, index);
|
||||
const disableResize = this.getNodeParameter('disableResize', index, false);
|
||||
|
||||
let response: IAirtopResponse;
|
||||
|
||||
const body: IDataObject = {
|
||||
url,
|
||||
...additionalFields,
|
||||
};
|
||||
|
||||
response = await apiRequest.call(this, 'POST', `/sessions/${sessionId}/windows`, body);
|
||||
|
||||
if (!response?.data?.windowId) {
|
||||
throw new NodeApiError(this.getNode(), {
|
||||
message: 'Failed to create window',
|
||||
code: 500,
|
||||
});
|
||||
}
|
||||
|
||||
const windowId = String(response.data.windowId);
|
||||
|
||||
if (getLiveView) {
|
||||
// Get Window info
|
||||
response = await apiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/sessions/${sessionId}/windows/${windowId}`,
|
||||
undefined,
|
||||
{
|
||||
...(includeNavigationBar && { includeNavigationBar: true }),
|
||||
...(screenResolution && { screenResolution }),
|
||||
...(disableResize && { disableResize: true }),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// validate response
|
||||
validateAirtopApiResponse(this.getNode(), response);
|
||||
|
||||
return this.helpers.returnJsonArray({ sessionId, windowId, ...response });
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { ERROR_MESSAGES } from '../../constants';
|
||||
import { validateAirtopApiResponse, validateSessionAndWindowId } from '../../GenericFunctions';
|
||||
import { apiRequest } from '../../transport';
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['window'],
|
||||
operation: ['getLiveView'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Include Navigation Bar',
|
||||
name: 'includeNavigationBar',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Whether to include the navigation bar in the Live View. When enabled, the navigation bar will be visible allowing you to navigate between pages.',
|
||||
},
|
||||
{
|
||||
displayName: 'Screen Resolution',
|
||||
name: 'screenResolution',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'The screen resolution of the Live View. Setting a resolution will force the window to open at that specific size.',
|
||||
placeholder: 'e.g. 1280x720',
|
||||
},
|
||||
{
|
||||
displayName: 'Disable Resize',
|
||||
name: 'disableResize',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to disable the window from being resized in the Live View',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const { sessionId, windowId } = validateSessionAndWindowId.call(this, index);
|
||||
const additionalFields = this.getNodeParameter('additionalFields', index);
|
||||
|
||||
const queryParams: Record<string, any> = {};
|
||||
|
||||
if (additionalFields.includeNavigationBar) {
|
||||
queryParams.includeNavigationBar = true;
|
||||
}
|
||||
|
||||
if (additionalFields.screenResolution) {
|
||||
const screenResolution = ((additionalFields.screenResolution as string) || '')
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
const regex = /^\d{3,4}x\d{3,4}$/; // Expected format: 1280x720
|
||||
|
||||
if (!regex.test(screenResolution)) {
|
||||
throw new NodeOperationError(this.getNode(), ERROR_MESSAGES.SCREEN_RESOLUTION_INVALID, {
|
||||
itemIndex: index,
|
||||
});
|
||||
}
|
||||
|
||||
queryParams.screenResolution = screenResolution;
|
||||
}
|
||||
|
||||
if (additionalFields.disableResize) {
|
||||
queryParams.disableResize = true;
|
||||
}
|
||||
|
||||
const response = await apiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/sessions/${sessionId}/windows/${windowId}`,
|
||||
undefined,
|
||||
queryParams,
|
||||
);
|
||||
|
||||
validateAirtopApiResponse(this.getNode(), response);
|
||||
|
||||
return this.helpers.returnJsonArray({ sessionId, windowId, ...response });
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import { validateAirtopApiResponse, validateSessionId } from '../../GenericFunctions';
|
||||
import { apiRequest } from '../../transport';
|
||||
|
||||
export const description: INodeProperties[] = [];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const sessionId = validateSessionId.call(this, index);
|
||||
|
||||
const response = await apiRequest.call(this, 'GET', `/sessions/${sessionId}/windows`, undefined);
|
||||
|
||||
validateAirtopApiResponse(this.getNode(), response);
|
||||
|
||||
return this.helpers.returnJsonArray({ sessionId, ...response });
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import {
|
||||
type IExecuteFunctions,
|
||||
type INodeExecutionData,
|
||||
type INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
validateRequiredStringField,
|
||||
validateSessionAndWindowId,
|
||||
validateUrl,
|
||||
validateAirtopApiResponse,
|
||||
} from '../../GenericFunctions';
|
||||
import { apiRequest } from '../../transport';
|
||||
import { urlField } from '../common/fields';
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
...urlField,
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['window'],
|
||||
operation: ['load'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['window'],
|
||||
operation: ['load'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Wait Until',
|
||||
name: 'waitUntil',
|
||||
type: 'options',
|
||||
default: 'load',
|
||||
description: "Wait until the specified loading event occurs. Defaults to 'Fully Loaded'.",
|
||||
options: [
|
||||
{
|
||||
name: 'Complete',
|
||||
value: 'complete',
|
||||
description: "Wait until the page and all it's iframes have loaded it's dom and assets",
|
||||
},
|
||||
{
|
||||
name: 'DOM Only Loaded',
|
||||
value: 'domContentLoaded',
|
||||
description: 'Wait until the dom has loaded',
|
||||
},
|
||||
{
|
||||
name: 'Fully Loaded',
|
||||
value: 'load',
|
||||
description: "Wait until the page dom and it's assets have loaded",
|
||||
},
|
||||
{
|
||||
name: 'No Wait',
|
||||
value: 'noWait',
|
||||
description: 'Do not wait for any loading event and will return immediately',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const { sessionId, windowId } = validateSessionAndWindowId.call(this, index);
|
||||
let url = validateRequiredStringField.call(this, index, 'url', 'URL');
|
||||
url = validateUrl.call(this, index);
|
||||
const additionalFields = this.getNodeParameter('additionalFields', index);
|
||||
|
||||
const response = await apiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/sessions/${sessionId}/windows/${windowId}`,
|
||||
{
|
||||
url,
|
||||
waitUntil: additionalFields.waitUntil,
|
||||
},
|
||||
);
|
||||
|
||||
validateAirtopApiResponse(this.getNode(), response);
|
||||
|
||||
return this.helpers.returnJsonArray({ sessionId, windowId, ...response });
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
IBinaryData,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
validateSessionAndWindowId,
|
||||
validateAirtopApiResponse,
|
||||
convertScreenshotToBinary,
|
||||
} from '../../GenericFunctions';
|
||||
import { apiRequest } from '../../transport';
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Output Binary Image',
|
||||
description: 'Whether to output the image as a binary file instead of a base64 encoded string',
|
||||
name: 'outputImageAsBinary',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['window'],
|
||||
operation: ['takeScreenshot'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const { sessionId, windowId } = validateSessionAndWindowId.call(this, index);
|
||||
const outputImageAsBinary = this.getNodeParameter('outputImageAsBinary', index, false) as boolean;
|
||||
|
||||
let data: IBinaryData | undefined; // for storing the binary data
|
||||
let image = ''; // for storing the base64 encoded image
|
||||
|
||||
const response = await apiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/sessions/${sessionId}/windows/${windowId}/screenshot`,
|
||||
);
|
||||
|
||||
// validate response
|
||||
validateAirtopApiResponse(this.getNode(), response);
|
||||
|
||||
// process screenshot on success
|
||||
if (response.meta?.screenshots?.length) {
|
||||
if (outputImageAsBinary) {
|
||||
const buffer = convertScreenshotToBinary(response.meta.screenshots[0]);
|
||||
data = await this.helpers.prepareBinaryData(buffer, 'screenshot.jpg', 'image/jpeg');
|
||||
} else {
|
||||
image = response?.meta?.screenshots?.[0].dataUrl;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
json: {
|
||||
sessionId,
|
||||
windowId,
|
||||
image,
|
||||
},
|
||||
...(data ? { binary: { data } } : {}),
|
||||
},
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user