Browse Source

fix: handle dialog not working

Ahmad Kholid 3 years ago
parent
commit
85477cbeb3

+ 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', {

+ 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();

+ 2 - 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,