AutomaApp / automa

A browser extension for automating your browser by connecting blocks
https://www.automa.site
Other
11.41k stars 1.23k forks source link

Trigger Automa's workflow through URL #1607

Closed wisinfun closed 8 months ago

wisinfun commented 9 months ago

Is your feature request related to a problem? Please describe. Triggering workflow through URLs can better integrate into computer workflow

Describe the solution you'd like I see that each workflow in Automa has a corresponding URL, such as chrome-extension://infppggnoaenmfagbfknfkancpbljcca/newtab.html#/workflows/PyhBPkFtxxxVseo1KdD. Can this workflow be run on this basis by using a suffix? It would be even better if external parameters could be passed through the URL, for example: chrome-extension://infppggnoaenmfagbfknfkancpbljcca/newtab.html#/workflows/PyhBPkFtxxxVseo1KdD/run/?argument=test

gvs42 commented 8 months ago

I am not able to get any parameters/variables into the workflow execution as stated in the documentation. The URL in the documentation is:

chrome-chrome-extension://infppggnoaenmfagbfknfkancpbljcca/execute.html#/workfloId?variableA=value&variableB=10

Issues:

Can you improve the documentation and check how to setup the parameter/variable injection?

zzph commented 8 months ago

I am in the same position, has anyone figured this out?

I tried many methods (as outlined here: https://docs.automa.site/workflow/variables.html).

I've tried: {{variables.myVar}}, $$myVar, and a few more- none work. Please help

zzph commented 8 months ago

I've found the problem, code needs to be updated. I tried opening a PR, but when pushing it says Permission to AutomaApp/automa.git denied

The issue:

Here, you are not correctly passing the search params from the URL: https://github.com/AutomaApp/automa/commit/5f1caf11735e2b0c55c6418918a3932e900451b2#diff-411f1a3a9aae65d635492a191d9577c3fd8fdeeb0a7726f050ad04d1c65e3453R13

Rather than doing this:

  searchParams.forEach((key, value) => {
    variables[key] = decodeURIComponent(value);
  });
  return { workflowId: workflowId ?? '', variables };

You can just do this:

  const variables = Object.fromEntries(searchParams);
  ...
  return { workflowId: workflowId ?? '', variables };
Kholid060 commented 7 months ago

Fixed in v1.28.27

marciofelipebr commented 4 months ago

I tried both ways and the variables are not passing, and I already have version 1.28.27

        window.dispatchEvent(new CustomEvent('__automaExecuteWorkflow', {detail: { 
            id: '8DSqeCvjHXm4AE1SZ59nH',
            data: {
                variables: {
                    name: 'John Doe',
                    search: 'Hello world'
                }
            } 
        }

OR

chrome-extension://infppggnoaenmfagbfknfkancpbljcca/execut.html#/8DSqeCvjHXm4AE1SZ59nH?name=value&search=10

BenJamesAndo commented 3 months ago

I kinda managed to pass a variable via a trigger URL. It seems you have to enter the value and then the variable. So instead of ?variableA=10 you have to do ?10=variableA It seems to only work with numbers and not letters. So 10 as a variable value works but ten doesn't. It kinda supports periods in the value, so 10.0 works but .10 doesn't.

Then to get that variable in the workflow you need to do {{variables.variableA}} instead of {{variables.$$variableA}}

Should I open this as a separate bug report?

eriksonssilva commented 3 months ago

I have found out that if you encapsulate the string between double quotes, it will work! So instead of chrome-extension://infppggnoaenmfagbfknfkancpbljcca/execute.html#/workflowId?variableA=value you would do chrome-extension://infppggnoaenmfagbfknfkancpbljcca/execute.html#/workflowId?"value"=variableA. Not sure why it's like that, but at least it's a workaround!

HuangKaibo2017 commented 4 days ago

can the workflow be called use this way?

const url = automaFetData('activeTabUrl', ''); // I can get full url in js code block by this way
// get a variable named keyword value from the url:
function extractVariable(url) {
  // Create a URL object to easily parse the URL
  const urlObj = new URL(url);
  // Extract the 'keyword' parameter value
  const keyword = urlObj.searchParams.get('keyword');
  // Decode the percent-encoded keyword back to UTF-8
  const decodedKeyword = decodeURIComponent(keyword);
  return decodedKeyword;
}
const keyword = extractVariable(url);