Ahmad Kholid il y a 3 ans
Parent
commit
275b708362

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "automa",
-  "version": "1.9.3",
+  "version": "1.9.4",
   "description": "An extension for automating your browser by connecting blocks",
   "license": "MIT",
   "repository": {

+ 1 - 1
src/background/workflowEngine/blocksHandler/handlerBrowserEvent.js

@@ -75,7 +75,7 @@ function onTabLoaded({ tabLoadedUrl, activeTabLoaded, timeout }, { id }) {
 
     setTimeout(() => {
       resolved = true;
-      resolve('');
+      reject(new Error('timeout'));
     }, timeout || 10000);
   });
 }

+ 1 - 0
src/background/workflowEngine/blocksHandler/handlerNewTab.js

@@ -47,6 +47,7 @@ async function newTab(block) {
     if (tab) {
       if (this.settings.debugMode || customUserAgent) {
         await attachDebugger(tab.id, this.activeTab.id);
+        this.debugAttached = true;
 
         if (customUserAgent) {
           await sendDebugCommand(tab.id, 'Network.setUserAgentOverride', {

+ 2 - 2
src/background/workflowEngine/blocksHandler/handlerProxy.js

@@ -25,7 +25,7 @@ function setProxy({ data, outputs }) {
       config.rules.singleProxy.host = data.host;
     } else {
       if (data.clearProxy) {
-        this.isUsingProxy = false;
+        this.engine.isUsingProxy = false;
 
         resolve({
           data: '',
@@ -47,7 +47,7 @@ function setProxy({ data, outputs }) {
     }
 
     chrome.proxy.settings.set({ value: config, scope: 'regular' }, () => {
-      this.isUsingProxy = true;
+      this.engine.isUsingProxy = true;
 
       resolve({
         data: data.host,

+ 1 - 0
src/background/workflowEngine/blocksHandler/handlerSwitchTab.js

@@ -34,6 +34,7 @@ export default async function ({ data, outputs }) {
 
   if (this.settings.debugMode) {
     await attachDebugger(tab.id, this.activeTab.id);
+    this.debugAttached = true;
   }
 
   this.activeTab.id = tab.id;

+ 15 - 5
src/background/workflowEngine/engine.js

@@ -54,7 +54,14 @@ class WorkflowEngine {
     };
 
     this.onDebugEvent = ({ tabId }, method, params) => {
-      if (tabId !== this.activeTab.id) return;
+      let isActiveTabEvent = false;
+      this.workers.forEach((worker) => {
+        if (isActiveTabEvent) return;
+
+        isActiveTabEvent = worker.activeTab.id === tabId;
+      });
+
+      if (!isActiveTabEvent) return;
 
       (this.eventListeners[method] || []).forEach((listener) => {
         listener(params);
@@ -237,10 +244,13 @@ class WorkflowEngine {
       if (this.workflow.settings.debugMode) {
         chrome.debugger.onEvent.removeListener(this.onDebugEvent);
 
-        if (this.activeTab.id) {
-          await sleep(1000);
-          chrome.debugger.detach({ tabId: this.activeTab.id });
-        }
+        await sleep(1000);
+
+        this.workers.forEach((worker) => {
+          if (!worker.debugAttached) return;
+
+          chrome.debugger.detach({ tabId: worker.activeTab.id });
+        });
       }
 
       const endedTimestamp = Date.now();

+ 8 - 0
src/background/workflowEngine/worker.js

@@ -21,6 +21,8 @@ class Worker {
     this.currentBlock = null;
     this.childWorkflowId = null;
 
+    this.debugAttached = false;
+
     this.activeTab = {
       url: '',
       frameId: 0,
@@ -212,7 +214,13 @@ class Worker {
           blockOnError.toDo === 'continue' ? 1 : 2
         );
         if (blockOnError.toDo !== 'error' && nextBlocks.connections) {
+          addBlockLog('error', {
+            message: error.message,
+            ...(error.data || {}),
+          });
+
           this.executeNextBlocks(nextBlocks.connections, prevBlockData);
+
           return;
         }
       }