Răsfoiți Sursa

chore: move to mv2

Ahmad Kholid 2 ani în urmă
părinte
comite
490cc393c8

+ 9 - 2
src/background/index.js

@@ -9,6 +9,8 @@ import BackgroundUtils from './BackgroundUtils';
 import BackgroundWorkflowUtils from './BackgroundWorkflowUtils';
 import BackgroundEventsListeners from './BackgroundEventsListeners';
 
+const isFirefox = BROWSER_TYPE === 'firefox';
+
 browser.alarms.onAlarm.addListener(BackgroundEventsListeners.onAlarms);
 
 browser.commands.onCommand.addListener(BackgroundEventsListeners.onCommand);
@@ -31,8 +33,7 @@ browser.webNavigation.onHistoryStateUpdated.addListener(
   BackgroundEventsListeners.onHistoryStateUpdated
 );
 
-const contextMenu =
-  BROWSER_TYPE === 'firefox' ? browser.menus : browser.contextMenus;
+const contextMenu = isFirefox ? browser.menus : browser.contextMenus;
 if (contextMenu && contextMenu.onClicked) {
   contextMenu.onClicked.addListener(
     BackgroundEventsListeners.onContextMenuClicked
@@ -228,4 +229,10 @@ if (!isMV2) {
   });
 
   keepAlive();
+} else if (!isFirefox) {
+  const sandboxIframe = document.createElement('iframe');
+  sandboxIframe.src = '/sandbox.html';
+  sandboxIframe.id = 'sandbox';
+
+  document.body.appendChild(sandboxIframe);
 }

+ 5 - 0
src/lib/tmpl.js

@@ -0,0 +1,5 @@
+import * as tmpl from '@n8n_io/riot-tmpl';
+
+tmpl.brackets.set('{{ }}');
+
+export default tmpl;

+ 10 - 22
src/manifest.chrome.json

@@ -1,13 +1,12 @@
 {
-  "manifest_version": 3,
+  "manifest_version": 2,
   "name": "Automa",
-  "action": {
+  "browser_action": {
     "default_popup": "popup.html",
     "default_icon": "icon-128.png"
   },
   "background": {
-    "service_worker": "background.bundle.js",
-    "type": "module"
+    "scripts": ["background.bundle.js"]
   },
   "icons": {
     "128": "icon-128.png"
@@ -52,29 +51,18 @@
     "alarms",
     "storage",
     "debugger",
-    "scripting",
+    "<all_urls>",
     "webNavigation",
     "unlimitedStorage"
   ],
-  "host_permissions": [
-    "<all_urls>"
-  ],
   "web_accessible_resources": [
-    {
-      "resources": [
-        "/elementSelector.css",
-        "/Inter-roman-latin.var.woff2",
-        "/icon-128.png",
-        "/locales/*",
-        "elementSelector.bundle.js"
-      ],
-      "matches": ["<all_urls>"]
-    }
+    "/elementSelector.css",
+    "/Inter-roman-latin.var.woff2",
+    "/icon-128.png",
+    "/locales/*",
+    "elementSelector.bundle.js"
   ],
   "sandbox": {
-    "pages": ["/sandbox.html"]
-  },
-  "content_security_policy": {
-    "sandbox": "sandbox allow-scripts allow-forms allow-popups allow-modals; script-src 'self' 'unsafe-inline' 'unsafe-eval'; child-src 'self';"
+    "pages": ["/sandbox.html", "uiSandbox.html"]
   }
 }

+ 1 - 3
src/sandbox/utils/handleBlockExpression.js

@@ -1,8 +1,6 @@
-import * as tmpl from '@n8n_io/riot-tmpl';
+import tmpl from '@/lib/tmpl';
 import functions from '@/workflowEngine/templating/templatingFunctions';
 
-tmpl.brackets.set('{{ }}');
-
 const templatingFunctions = Object.keys(functions).reduce((acc, funcName) => {
   acc[`$${funcName}`] = functions[funcName];
 

+ 4 - 1
src/workflowEngine/templating/renderString.js

@@ -1,7 +1,9 @@
+import browser from 'webextension-polyfill';
 import { messageSandbox } from '../helper';
 import mustacheReplacer from './mustacheReplacer';
 
 const isFirefox = BROWSER_TYPE === 'firefox';
+const isMV2 = browser.runtime.getManifest().manifest_version === 2;
 
 export default async function (str, data, isPopup = true) {
   if (!str || typeof str !== 'string') return '';
@@ -16,7 +18,8 @@ export default async function (str, data, isPopup = true) {
 
   let renderedValue = {};
   const evaluateJS = str.startsWith('!!');
-  if (evaluateJS && !isFirefox && isPopup) {
+
+  if (evaluateJS && !isFirefox && (isMV2 || isPopup)) {
     const refKeysRegex =
       /(variables|table|secrets|loopData|workflow|googleSheets|globalData)@/g;
     const strToRender = str.replace(refKeysRegex, '$1.');