Browse Source

feat: update extension manifest

Ahmad Kholid 1 year ago
parent
commit
314146d888

+ 1 - 44
src/background/index.js

@@ -204,50 +204,7 @@ automa('background', message);
 
 browser.runtime.onMessage.addListener(message.listener());
 
-/* eslint-disable no-use-before-define */
-
-const isMV2 = browser.runtime.getManifest().manifest_version === 2;
-let lifeline;
-async function keepAlive() {
-  if (lifeline) return;
-  for (const tab of await browser.tabs.query({ url: '*://*/*' })) {
-    try {
-      await browser.scripting.executeScript({
-        target: { tabId: tab.id },
-        func: () => chrome.runtime.connect({ name: 'keepAlive' }),
-      });
-      browser.tabs.onUpdated.removeListener(retryOnTabUpdate);
-      return;
-    } catch (e) {
-      // Do nothing
-    }
-  }
-  browser.tabs.onUpdated.addListener(retryOnTabUpdate);
-}
-async function retryOnTabUpdate(tabId, info) {
-  if (info.url && /^(file|https?):/.test(info.url)) {
-    keepAlive();
-  }
-}
-function keepAliveForced() {
-  lifeline?.disconnect();
-  lifeline = null;
-  keepAlive();
-}
-
-if (!isMV2) {
-  browser.runtime.onConnect.addListener((port) => {
-    if (port.name === 'keepAlive') {
-      lifeline = port;
-      /* eslint-disable-next-line */
-      console.log('Stayin alive: ', new Date());
-      setTimeout(keepAliveForced, 295e3);
-      port.onDisconnect.addListener(keepAliveForced);
-    }
-  });
-
-  keepAlive();
-} else if (!isFirefox) {
+if (!isFirefox) {
   const sandboxIframe = document.createElement('iframe');
   sandboxIframe.src = '/sandbox.html';
   sandboxIframe.id = 'sandbox';

+ 2 - 2
src/locales/zh/blocks.json

@@ -210,7 +210,7 @@
         "actions": {
           "press-key": "按下一个按键",
           "multiple-keys": "按下多个按键"
-        }
+        },
         "press-time": "按下时间 (毫秒)"
       },
       "save-assets": {
@@ -807,4 +807,4 @@
       }
     }
   }
-}
+}

+ 1 - 1
src/locales/zh/common.json

@@ -47,7 +47,7 @@
     "password": "密码",
     "category": "分类",
     "optional": "可选",
-    "0disable": "0 到禁用"
+    "0disable": "0 到禁用",
     "millisecond": "毫秒 | 毫秒"
   },
   "message": {

+ 23 - 15
src/manifest.chrome.json

@@ -1,12 +1,13 @@
 {
-  "manifest_version": 2,
+  "manifest_version": 3,
   "name": "Automa",
-  "browser_action": {
+  "action": {
     "default_popup": "popup.html",
     "default_icon": "icon-128.png"
   },
   "background": {
-    "scripts": ["background.bundle.js"]
+    "service_worker": "background.bundle.js",
+    "type": "module"
   },
   "icons": {
     "128": "icon-128.png"
@@ -27,6 +28,7 @@
       "description": "Open element picker"
     }
   },
+  "host_permissions": ["<all_urls>"],
   "content_scripts": [
     {
       "matches": ["<all_urls>"],
@@ -47,32 +49,38 @@
     }
   ],
   "optional_permissions": [
-    "clipboardRead",
+    "cookies",
     "downloads",
     "contextMenus",
-    "notifications",
-    "cookies"
+    "clipboardRead",
+    "notifications"
   ],
   "permissions": [
     "tabs",
-    "activeTab",
     "proxy",
     "alarms",
     "storage",
     "debugger",
-    "<all_urls>",
+    "activeTab",
+    "offscreen",
     "webNavigation",
     "unlimitedStorage"
   ],
   "web_accessible_resources": [
-    "/elementSelector.css",
-    "/Inter-roman-latin.var.woff2",
-    "/icon-128.png",
-    "/locales/*",
-    "elementSelector.bundle.js"
+    {
+      "resources": [
+        "/locales/*",
+        "/icon-128.png",
+        "/elementSelector.css",
+        "elementSelector.bundle.js",
+        "/Inter-roman-latin.var.woff2"
+      ],
+      "matches": [
+        "*://*/*"
+      ]
+    }
   ],
   "sandbox": {
     "pages": ["/sandbox.html"]
-  },
-  "content_security_policy": "script-src 'self' https://apis.google.com/ https://accounts.google.com/ https://www.googleapis.com https://ajax.googleapis.com; object-src 'self'"
+  }
 }

+ 11 - 0
src/offscreen/index.html

@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Offscreen</title>
+</head>
+<body>
+
+</body>
+</html>

+ 0 - 0
src/offscreen/index.js


+ 3 - 0
src/workflowEngine/BrowserApi.js

@@ -0,0 +1,3 @@
+class BrowserAPI {}
+
+export default BrowserAPI;