Skip to content

Commit

Permalink
issue #109 - convert the main build to MV3 and remove the flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Manvel committed Mar 30, 2024
1 parent 2ed6bbf commit eba92d8
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 121 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/running-tests-mv3.yml

This file was deleted.

4 changes: 0 additions & 4 deletions src/js/background/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ async function actionExecution(instruction)
}
case "cs-inject":
case "inject": {
if (!process.env.MV3) {
await messageContentScript(instruction, cba.clipboard);
break;
}
const playingTabId = await cba.getPlayingTabId();
if (!playingTabId) {
throw new Error("No playing tab");
Expand Down
5 changes: 2 additions & 3 deletions src/js/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
/** @global */
globalThis.browser = require("webextension-polyfill");

if (!process.env.MV3) {
require("../analytics");
}
// see: https://github.com/browser-automation/cba/issues/127
// require("../analytics");
const {CBA} = require("./CBA");
const {playProject} = require("./actions");
const projectsDb = require("../db/projects");
Expand Down
5 changes: 1 addition & 4 deletions src/js/background/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@
*/

export function setBadgeText(text) {
if (process.env.MV3) {
return browser.action.setBadgeText({text});
}
return browser.browserAction.setBadgeText({text});
return browser.action.setBadgeText({text});
}
32 changes: 1 addition & 31 deletions src/js/cs/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ browser.runtime.onMessage.addListener((request) => {
}
});

async function executeAction(recordRow, request)
async function executeAction(recordRow)
{
const {type, inputs} = recordRow;
const [input1, input2] = inputs;
Expand Down Expand Up @@ -76,36 +76,6 @@ async function executeAction(recordRow, request)
window.location = input1;
break;
}
case "inject": {
// TODO: Remove when moved to MV3 is complete.
const clipboardId = "grabClipboardHere";
const script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = `
var clipboard=${JSON.stringify(request.clipboard)};
${input1};
var newdiv = document.createElement('div');
if(document.getElementById('${clipboardId}')!= null) {
document.getElementById('${clipboardId}').textContent = JSON.stringify(clipboard);
}
else {
newdiv.setAttribute('id', '${clipboardId}');
newdiv.textContent = JSON.stringify(clipboard);
document.body.appendChild(newdiv);
}
document.getElementById('${clipboardId}').style.display = 'none';`;
document.documentElement.appendChild(script); // run the script
document.documentElement.removeChild(script); // clean up
const injectedClipboard = document.querySelector(`#${clipboardId}`);
if(injectedClipboard) {
clipboard = JSON.parse(injectedClipboard.textContent);
}
break;
}
case "cs-inject": {
await eval(`(async () => {${input1}})()`);
break;
}
case "copy": {
const targetElement = document.querySelector(input1);
if(targetElement) {
Expand Down
3 changes: 2 additions & 1 deletion src/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* <http://www.gnu.org/licenses/>.
*/

require("./analytics");
// see: https://github.com/browser-automation/cba/issues/127
// require("../analytics");
require("./ui/import-export");
require("./ui/functions");
require("./ui/tabs");
Expand Down
6 changes: 5 additions & 1 deletion src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
* <http://www.gnu.org/licenses/>.
*/

const {_gaq} = require("./analytics");
// see: https://github.com/browser-automation/cba/issues/127
// const {_gaq} = require("./analytics");
require("./ui/projects");

/*
see: https://github.com/browser-automation/cba/issues/127
function trackButtonClick(e) {
_gaq.push(['_trackEvent', e.target.id, 'clicked']);
}
Expand All @@ -32,6 +35,7 @@ function analytAllButtons() {
}
analytAllButtons();
*/

const params = (new URL(window.location)).searchParams;
if (params.has("options")) {
Expand Down
2 changes: 1 addition & 1 deletion src/manifest/mv3.json → src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
"permissions": ["cookies", "tabs", "storage", "scripting"],
"update_url": "https://clients2.google.com/service/update2/crx",
"version": "9.1.0"
}
}
29 changes: 0 additions & 29 deletions src/manifest/mv2.json

This file was deleted.

8 changes: 0 additions & 8 deletions tests/tests/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,4 @@ 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};
18 changes: 5 additions & 13 deletions tests/tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,19 +527,11 @@ async function resetCbaObject()

async function getBadgeText()
{
if (process.env.MV3) {
return backgroundPage().evaluate(() => {
return new Promise((response) => {
chrome.action.getBadgeText({}, response);
})
});
} else {
return backgroundPage().evaluate(() => {
return new Promise((response) => {
chrome.browserAction.getBadgeText({}, response);
})
});
}
return backgroundPage().evaluate(() => {
return new Promise((response) => {
chrome.action.getBadgeText({}, response);
})
});
}

// Usage: await setListeners("#id", ["mousedown", "click"], (e) => {});
Expand Down
5 changes: 1 addition & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,9 @@ 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`,
{ from: `./src/manifest.json`,
to: "manifest.json" },
]}),
new webpack.EnvironmentPlugin({
MV3: process.env.MV3 || 0
})
]
};

Expand Down

0 comments on commit eba92d8

Please sign in to comment.