Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 authored Mar 7, 2022
2 parents f4ede85 + 7ecebed commit 79cae69
Show file tree
Hide file tree
Showing 41 changed files with 1,061 additions and 153 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "automa",
"version": "1.2.1",
"version": "1.3.0",
"description": "An extension for automating your browser by connecting blocks",
"license": "MIT",
"repository": {
Expand Down
16 changes: 9 additions & 7 deletions src/background/collection-engine/flow-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ export function workflow(flow) {
blocksHandler,
states: this.states,
logger: this.logger,
parentWorkflow: {
id: this.id,
isCollection: true,
name: this.collection.name,
},
data: {
globalData: globalData.trim() === '' ? null : globalData,
options: {
parentWorkflow: {
id: this.id,
isCollection: true,
name: this.collection.name,
},
data: {
globalData: globalData.trim() === '' ? null : globalData,
},
},
});

Expand Down
19 changes: 12 additions & 7 deletions src/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const workflow = {
}

const engine = new WorkflowEngine(workflowData, {
...options,
options,
blocksHandler,
logger: this.logger,
states: this.states,
Expand Down Expand Up @@ -155,7 +155,7 @@ async function checkVisitWebTriggers(changeInfo, tab) {
if (triggeredWorkflow) {
const workflowData = await workflow.get(triggeredWorkflow.id);

if (workflowData) workflow.execute(workflowData);
if (workflowData) workflow.execute(workflowData, { tabId: tab.id });
}
}
async function checkRecordingWorkflow({ status }, { url, id }) {
Expand Down Expand Up @@ -353,13 +353,18 @@ message.on('set:active-tab', (tabId) => {
return browser.tabs.update(tabId, { active: true });
});

message.on('get:sender', (_, sender) => {
return sender;
});
message.on('get:tab-screenshot', (options) => {
return browser.tabs.captureVisibleTab(options);
message.on('debugger:send-command', ({ tabId, method, params }) => {
return new Promise((resolve) => {
console.log(tabId, method, params);
chrome.debugger.sendCommand({ tabId }, method, params, resolve);
});
});

message.on('get:sender', (_, sender) => sender);
message.on('get:file', (path) => getFile(path));
message.on('get:tab-screenshot', (options) =>
browser.tabs.captureVisibleTab(options)
);

message.on('collection:execute', (collection) => {
const engine = new CollectionEngine(collection, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ async function executeWorkflow({ outputs, data }) {
throw errorInstance;
}
const options = {
parentWorkflow: {
id: this.id,
name: this.workflow.name,
options: {
data: {
globalData: isWhitespace(data.globalData) ? null : data.globalData,
},
parentWorkflow: {
id: this.id,
name: this.workflow.name,
},
},
events: {
onInit: (engine) => {
Expand All @@ -77,9 +82,6 @@ async function executeWorkflow({ outputs, data }) {
states: this.states,
logger: this.logger,
blocksHandler: this.blocksHandler,
data: {
globalData: isWhitespace(data.globalData) ? null : data.globalData,
},
};

if (workflow.drawflow.includes(this.workflow.id)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { getBlockConnection, attachDebugger } from '../helper';

export async function hoverElement(block) {
const nextBlockId = getBlockConnection(block);

try {
if (!this.activeTab.id) throw new Error('no-tab');

const { debugMode, executedBlockOnWeb } = this.workflow.settings;

if (!debugMode) {
await attachDebugger(this.activeTab.id);
}

await this._sendMessageToTab({
...block,
debugMode,
executedBlockOnWeb,
activeTabId: this.activeTab.id,
frameSelector: this.frameSelector,
});

if (!debugMode) {
chrome.debugger.detach({ tabId: this.activeTab.id });
}

return {
data: '',
nextBlockId,
};
} catch (error) {
error.nextBlockId = nextBlockId;

throw error;
}
}

export default hoverElement;
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ async function interactionHandler(block, { refData }) {
const nextBlockId = getBlockConnection(block);
const messagePayload = {
...block,
refData,
debugMode,
executedBlockOnWeb,
activeTabId: this.activeTab.id,
frameSelector: this.frameSelector,
};

if (block.name === 'javascript-code') messagePayload.refData = refData;

try {
const data = await this._sendMessageToTab(messagePayload, {
frameId: this.activeTab.frameId || 0,
Expand Down Expand Up @@ -80,13 +82,7 @@ async function interactionHandler(block, { refData }) {
}
}

const isJavascriptBlock = block.name === 'javascript-code';

if (block.data.assignVariable && !isJavascriptBlock) {
this.referenceData.variables[block.data.variableName] = data;
}

if (isJavascriptBlock) {
if (block.name === 'javascript-code') {
if (data?.variables) {
Object.keys(data.variables).forEach((varName) => {
this.referenceData.variables[varName] = data.variables[varName];
Expand All @@ -99,6 +95,8 @@ async function interactionHandler(block, { refData }) {
: [data.columns.data];
this.addDataToColumn(arrData);
}
} else if (block.data.assignVariable) {
this.referenceData.variables[block.data.variableName] = data;
}

return {
Expand Down
28 changes: 26 additions & 2 deletions src/background/workflow-engine/blocks-handler/handler-new-tab.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import browser from 'webextension-polyfill';
import { getBlockConnection } from '../helper';
import {
getBlockConnection,
attachDebugger,
sendDebugCommand,
} from '../helper';
import { isWhitespace } from '@/utils/helper';

async function newTab(block) {
Expand All @@ -14,7 +18,8 @@ async function newTab(block) {
const nextBlockId = getBlockConnection(block);

try {
const { updatePrevTab, url, active, inGroup } = block.data;
const { updatePrevTab, url, active, inGroup, customUserAgent, userAgent } =
block.data;
const isInvalidUrl = !/^https?/.test(url);

if (isInvalidUrl) {
Expand All @@ -40,6 +45,21 @@ async function newTab(block) {

this.activeTab.url = url;
if (tab) {
if (this.workflow.settings.debugMode || customUserAgent) {
await attachDebugger(tab.id, this.activeTab.id);

if (customUserAgent) {
const res = await sendDebugCommand(
tab.id,
'Network.setUserAgentOverride',
{
userAgent,
}
);
console.log('agent:', res);
}
}

this.activeTab.id = tab.id;
this.windowId = tab.windowId;
}
Expand All @@ -63,6 +83,10 @@ async function newTab(block) {

this.activeTab.frameId = 0;

if (!this.workflow.settings.debugMode && customUserAgent) {
chrome.debugger.detach({ tabId: tab.id });
}

return {
data: url,
nextBlockId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import browser from 'webextension-polyfill';
import { getBlockConnection } from '../helper';
import { getBlockConnection, attachDebugger } from '../helper';

export default async function ({ data, outputs }) {
const nextBlockId = getBlockConnection({ outputs });
Expand Down Expand Up @@ -32,6 +32,10 @@ export default async function ({ data, outputs }) {
await browser.tabs.update(tab.id, { active: true });
}

if (this.workflow.settings.debugMode) {
await attachDebugger(tab.id, this.activeTab.id);
}

this.activeTab.id = tab.id;
this.activeTab.frameId = 0;
this.activeTab.url = tab.url;
Expand Down
Loading

0 comments on commit 79cae69

Please sign in to comment.