Browse Source

fix: key not typed when triggering the keyboard event

Ahmad Kholid 3 years ago
parent
commit
0ce19478b1

+ 2 - 1
src/background/workflowEngine/helper.js

@@ -22,7 +22,8 @@ export function waitTabLoaded(tabId, ms = 10000) {
     const timeout = null;
     let isResolved = false;
     const onErrorOccurred = (details) => {
-      if (details.tabId !== tabId) return;
+      if (details.tabId !== tabId || detail.error.includes('ERR_ABORTED'))
+        return;
 
       isResolved = true;
       browser.webNavigation.onErrorOccurred.removeListener(onErrorOccurred);

+ 15 - 3
src/content/blocksHandler/handlerTriggerEvent.js

@@ -1,6 +1,7 @@
 import { sendMessage } from '@/utils/message';
 import simulateEvent from '@/utils/simulateEvent';
 import simulateMouseEvent from '@/utils/simulateEvent/mouseEvent';
+import { keyDefinitions } from '@/utils/USKeyboardLayout';
 import { getElementPosition } from '../utils';
 import handleSelector from '../handleSelector';
 
@@ -39,6 +40,8 @@ const eventHandlers = {
     await mouseEvents[eventName]();
   },
   'keyboard-event': async ({ name, params, sendCommand }) => {
+    const definition = keyDefinitions[params?.key];
+
     const commandParams = {
       key: params.key ?? '',
       code: params.code ?? '',
@@ -47,6 +50,10 @@ const eventHandlers = {
       type: name === 'keyup' ? 'keyUp' : 'keyDown',
     };
 
+    if (definition.text || params.key.length === 1) {
+      commandParams.text = definition.text || params.key;
+    }
+
     Object.keys(modifiers).forEach((key) => {
       if (commandParams.modifiers) return;
       if (params[key]) commandParams.modifiers = modifiers[key];
@@ -65,13 +72,18 @@ function triggerEvent({ data, id, frameSelector, debugMode, activeTabId }) {
           const eventHandler = eventHandlers[data.eventType];
 
           if (debugMode && eventHandler) {
-            const elCoordinate = await getElementPosition(element);
+            let elCoordinate = {};
+
+            if (data.eventType === 'mouse-event') {
+              const { x, y } = await getElementPosition(element);
+              elCoordinate = { x, y };
+            }
+
             const sendCommand = (method, params = {}) => {
               const payload = {
                 method,
                 params: {
-                  x: elCoordinate.x,
-                  y: elCoordinate.y,
+                  ...elCoordinate,
                   ...params,
                 },
                 tabId: activeTabId,