ソースを参照

fix: frame id not found error when iframe redirect (#1640)

Ahmad Kholid 1 年間 前
コミット
ac13c3faa1
1 ファイル変更19 行追加4 行削除
  1. 19 4
      src/workflowEngine/blocksHandler/handlerSwitchTo.js

+ 19 - 4
src/workflowEngine/blocksHandler/handlerSwitchTo.js

@@ -1,4 +1,4 @@
-import { objectHasKey, sleep } from '@/utils/helper';
+import { sleep } from '@/utils/helper';
 import { getFrames } from '../helper';
 
 async function switchTo(block) {
@@ -31,14 +31,29 @@ async function switchTo(block) {
 
     const frames = await getFrames(this.activeTab.id);
 
-    if (objectHasKey(frames, url)) {
-      this.activeTab.frameId = frames[url];
+    let frameId = frames[url] ?? null;
+    if (frameId === null) {
+      // Incase the iframe is redirect
+      frameId = Object.entries(frames).find(([frameURL]) => {
+        try {
+          const currFramePathName = new URL(url).pathname;
+          const framePathName = new URL(frameURL).pathname;
+
+          return currFramePathName === framePathName;
+        } catch (error) {
+          return false;
+        }
+      })?.[1];
+    }
+
+    if (frameId !== null) {
+      this.activeTab.frameId = frameId;
 
       await sleep(1000);
 
       return {
-        data: this.activeTab.frameId,
         nextBlockId,
+        data: this.activeTab.frameId,
       };
     }