From 11981d1df04438db644b12a66bf146b4b80cf283 Mon Sep 17 00:00:00 2001 From: Manvel Saroyan Date: Sat, 30 Dec 2023 19:49:44 +0400 Subject: [PATCH] Issue #128 - separate codepath for MV2 and MV3 (#129) --- .github/workflows/running-tests-mv3.yml | 22 ++++++++++++++++++ src/{manifest.json => manifest/mv2.json} | 0 src/manifest/mv3.json | 29 ++++++++++++++++++++++++ tests/tests/generic.js | 8 +++++++ webpack.config.js | 8 ++++++- 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/running-tests-mv3.yml rename src/{manifest.json => manifest/mv2.json} (100%) create mode 100644 src/manifest/mv3.json diff --git a/.github/workflows/running-tests-mv3.yml b/.github/workflows/running-tests-mv3.yml new file mode 100644 index 0000000..3a57be0 --- /dev/null +++ b/.github/workflows/running-tests-mv3.yml @@ -0,0 +1,22 @@ +name: Tests MV3 + +on: + - push + +jobs: + run-puppeteer: + name: Run tests MV3 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Node + uses: actions/setup-node@v2 + + - name: Prepare dependencies + run: sudo apt-get install xvfb && npm install + + - name: Run linters + run: npm run lint + + - name: Run tests MV3 + run: MV3=1 xvfb-run npm test diff --git a/src/manifest.json b/src/manifest/mv2.json similarity index 100% rename from src/manifest.json rename to src/manifest/mv2.json diff --git a/src/manifest/mv3.json b/src/manifest/mv3.json new file mode 100644 index 0000000..eb44edb --- /dev/null +++ b/src/manifest/mv3.json @@ -0,0 +1,29 @@ +{ + "background": { + "scripts": ["js/back.js"], + "persistent": false + }, + "browser_action": { + "default_icon": "logo.png", + "default_popup": "popup.html" + }, + "content_scripts": [ { + "all_frames": true, + "js": ["js/browser-polyfill.min.js", "js/jquery-1.7.2.min.js", "js/cs.js"], + "matches": [ "https://*/*", "http://*/*" ], + "run_at": "document_end" + } ], + "content_security_policy": "script-src 'self' 'unsafe-eval' https://ssl.google-analytics.com; object-src 'self'", + "description": "Extension for automating chromium browser, Create project -> Record -> Edit Automation -> Manage -> Play (MV3)", + "icons": { + "128": "css/icons/128x128.png", + "16": "css/icons/16x16.png", + "48": "css/icons/48x48.png" + }, + "manifest_version": 2, + "name": "Chromium browser automation", + "options_page": "options.html", + "permissions": ["cookies", "http://*/*", "https://*/*", "tabs", "storage"], + "update_url": "https://clients2.google.com/service/update2/crx", + "version": "9.1.0" +} diff --git a/tests/tests/generic.js b/tests/tests/generic.js index a524318..68f9808 100644 --- a/tests/tests/generic.js +++ b/tests/tests/generic.js @@ -74,4 +74,12 @@ it("Sending highlight and unHighlight event should outline specific element acco equal(await getStyle(query, "outline"), ""); }); +if (process.env.MV3) +{ + it("Run MV3 test", async() => + { + equal(process.env.MV3, "1"); + }); +} + module.exports = {pageSetup}; diff --git a/webpack.config.js b/webpack.config.js index bfb50ec..993c5c1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -22,6 +22,7 @@ const argv = require("minimist")(process.argv.slice(2)); const CopyPlugin = require('copy-webpack-plugin'); const {minify} = require("csso"); const {extname} = require("path"); +const webpack = require("webpack"); const transformCss = (content, file) => { @@ -57,7 +58,12 @@ module.exports = { from: "./src/js/jquery*.js", to: "js/jquery-1.7.2.min.js" }, {from: "node_modules/webextension-polyfill/dist/browser-polyfill.min.js", to: "js" }, - ]}) + { from: `./src/manifest/${process.env.MV3 ? "mv3" : "mv2"}.json`, + to: "manifest.json" }, + ]}), + new webpack.EnvironmentPlugin({ + MV3: process.env.MV3 || 0 + }) ] };