Skip to content

Commit

Permalink
issue #141 - execute inject action when cs-inject is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Manvel committed Mar 29, 2024
1 parent 46a9be9 commit ec289e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/js/cs/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ async function executeAction(recordRow, request)
window.location = input1;
break;
}
case "cs-inject":
case "inject": {
// TODO: Remove when moved to MV3 is complete.
const clipboardId = "grabClipboardHere";
const script = document.createElement('script');
script.setAttribute("type", "application/javascript");
Expand All @@ -102,10 +102,10 @@ async function executeAction(recordRow, request)
}
break;
}
case "cs-inject": {
await eval(`(async () => {${input1}})()`);
break;
}
// case "cs-inject": {
// await eval(`(async () => {${input1}})()`);
// break;
// }
case "copy": {
const targetElement = document.querySelector(input1);
if(targetElement) {
Expand Down
16 changes: 9 additions & 7 deletions tests/tests/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ const pageSetup = {
path: server
}

const itIfMV2 = !process.env.MV3 ? it : it.skip;

beforeEach(async () =>
{
const pageUrl = await getPageUrl();
Expand Down Expand Up @@ -105,7 +103,7 @@ it("Executing project with bg-inject skips the bg-inject execution", async() =>
equal(await getTextContent("#changeContent"), newText);
});

itIfMV2("cs-inject function runs specified script in content script", async() =>
it("cs-inject function runs specified script in content script", async() =>
{
const newText = "CS injected text";
const evType = "cs-inject";
Expand All @@ -114,7 +112,10 @@ itIfMV2("cs-inject function runs specified script in content script", async() =>
equal(await getTextContent("#changeContent"), newText);
});

itIfMV2("cs-inject action executes script with async(await) code before moving to the next action", async() =>
/*
Can't support unless https://github.com/w3c/webextensions/pull/540 is implemented
by the browsers.
it("cs-inject action executes script with async(await) code before moving to the next action", async() =>
{
const evType = "cs-inject";
const valuePromise = "Promise action has been played";
Expand All @@ -134,14 +135,15 @@ itIfMV2("cs-inject action executes script with async(await) code before moving t
equal(await getTextContent("#changeContent"), valuePromise+valueSync);
});
itIfMV2("Jquery is accessible through cs-inject", async() =>
it("Jquery is accessible through cs-inject", async() =>
{
const newText = "Jquery in CS injected text";
const query = "#changeContent";
const action = createAction(`$("${query}").text("${newText}")`, "cs-inject", "");
await playTestProject([action]);
equal(await getTextContent(query), newText);
});
*/

it("bg-function should execute predefined function and play next action when/if defined in function", async() =>
{
Expand Down Expand Up @@ -376,7 +378,7 @@ it("Pause action pauses the workflow until the project is played again and set '
equal(await getBadgeText(), "");
});

itIfMV2("Clipboard set in inject should be accessible in cs-inject", async() =>
it("Clipboard set in inject should be accessible in cs-inject", async() =>
{
const clipboardValue = "cba-test-value";
const clipboardName = "cba-test";
Expand All @@ -387,7 +389,7 @@ itIfMV2("Clipboard set in inject should be accessible in cs-inject", async() =>
equal(await getTextContent("#changeContent"), clipboardValue);
});

itIfMV2("Clipboard set in cs-inject should be accessible in inject", async() =>
it("Clipboard set in cs-inject should be accessible in inject", async() =>
{
const clipboardValue = "cba-test-value";
const clipboardName = "cba-test";
Expand Down

0 comments on commit ec289e0

Please sign in to comment.