浏览代码

fix: workflow stuck when tab is updating

Ahmad Kholid 3 年之前
父节点
当前提交
7bb03f12f8

+ 0 - 1
src/background/workflow-engine/blocks-handler/handler-google-sheets.js

@@ -43,7 +43,6 @@ export default async function ({ data, outputs }) {
     };
   } catch (error) {
     error.nextBlockId = nextBlockId;
-    console.log(error.message, 'halo');
 
     throw error;
   }

+ 10 - 5
src/background/workflow-engine/engine.js

@@ -46,7 +46,7 @@ function tabUpdatedHandler(tabId, changeInfo, tab) {
       clearTimeout(reloadTimeout);
       reloadTimeout = null;
 
-      executeContentScript(tabId, 'update tab')
+      executeContentScript(tabId)
         .then((frames) => {
           this.tabId = tabId;
           this.frames = frames;
@@ -96,7 +96,7 @@ class WorkflowEngine {
     this.isPaused = false;
     this.isDestroyed = false;
     this.isUsingProxy = false;
-    this.frameId = null;
+    this.frameId = 0;
     this.windowId = null;
     this.tabGroupId = null;
     this.currentBlock = null;
@@ -311,9 +311,13 @@ class WorkflowEngine {
   _blockHandler(block, prevBlockData) {
     if (this.isDestroyed) return;
     if (this.isPaused) {
-      setTimeout(() => {
-        this._blockHandler(block, prevBlockData);
-      }, 1000);
+      browser.tabs.get(this.tabId).then(({ status }) => {
+        this.isPaused = status !== 'complete';
+
+        setTimeout(() => {
+          this._blockHandler(block, prevBlockData);
+        }, 1000);
+      });
 
       return;
     }
@@ -356,6 +360,7 @@ class WorkflowEngine {
         .then((result) => {
           clearTimeout(this.workflowTimeout);
           this.workflowTimeout = null;
+
           this.addLog({
             type: 'success',
             name: block.name,

+ 3 - 2
src/background/workflow-engine/execute-content-script.js

@@ -34,11 +34,12 @@ async function contentScriptExist(tabId, frameId = 0) {
 
 export default async function (tabId, frameId = 0) {
   try {
-    const isScriptExists = await contentScriptExist(tabId, frameId);
+    const currentFrameId = typeof frameId !== 'number' ? 0 : frameId;
+    const isScriptExists = await contentScriptExist(tabId, currentFrameId);
 
     if (!isScriptExists) {
       await browser.tabs.executeScript(tabId, {
-        frameId,
+        frameId: currentFrameId,
         file: './contentScript.bundle.js',
       });
     }

+ 1 - 2
src/content/index.js

@@ -6,13 +6,12 @@ import blocksHandler from './blocks-handler';
 (() => {
   if (window.isAutomaInjected) return;
 
-  console.log(window.isAutomaInjected);
   window.isAutomaInjected = true;
 
   browser.runtime.onMessage.addListener((data) => {
     if (data.isBlock) {
       const handler = blocksHandler[toCamelCase(data.name)];
-      console.log(data);
+
       if (handler) {
         return handler(data);
       }