Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefow wokflow event don't run with JS #1814

Open
open1999 opened this issue Aug 31, 2024 · 2 comments
Open

Firefow wokflow event don't run with JS #1814

open1999 opened this issue Aug 31, 2024 · 2 comments

Comments

@open1999
Copy link

Hello,

If we create a Javascript script in "Settings-Worflow Event- on action Finish (fail or success)."

The Javascript script is never triggered. No error (of course).

If we use httprequest it works.

Under Chrome everything works (Httprequest) and of course the same JS script.

Same problem with Firefox and Linux.

The code JS

`const workflow = automaRefData('workflow');
const wfl = workflow.logs;
const workflowlast = wfl[wfl.length-1];

const date1 = new Date();

const datefr = date1.toLocaleString('fr-FR',{
weekday: 'short',
day: 'numeric',
month: 'short',
year: '2-digit',
hour: 'numeric',
minute: 'numeric',
second: 'numeric'});

fetch("http://192.168.100.18:8089/api/webhook/tokenxxxx", {
method: "POST",
body: JSON.stringify({
Status: workflow.status,
ErrorBlock: workflowlast,
ErrorMessage: workflow.errorMessage,
DateError: datefr
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
});`

Firefox : 129
Windows : 10
Automa : 1.28.27

Thanks

@jingbof
Copy link

jingbof commented Sep 4, 2024

If you're executing the script as background script, I'd suggest adding a global try-catch block to print the error to the console. Then follow the help doc to find the output by opening Chrome DevTools on the Automa dashboard.

(Also might need to add automaNextBlock() at the end if there are more blocks after this JavaScript code block)

try {
    const workflow = automaRefData('workflow');
    const wfl = workflow.logs;
    const workflowlast = wfl[wfl.length - 1];

    const date1 = new Date();

    const datefr = date1.toLocaleString('fr-FR', {
        weekday: 'short',
        day: 'numeric',
        month: 'short',
        year: '2-digit',
        hour: 'numeric',
        minute: 'numeric',
        second: 'numeric'
    });

    fetch("http://192.168.100.18:8089/api/webhook/tokenxxxx", {
        method: "POST",
        body: JSON.stringify({
            Status: workflow.status,
            ErrorBlock: workflowlast,
            ErrorMessage: workflow.errorMessage,
            DateError: datefr
        }),
        headers: {
            "Content-type": "application/json; charset=UTF-8"
        }
    }).then(response => {
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        return response.json();
    }).then(data => {
        console.log('Success:', data);
    }).catch(error => {
        console.error('Fetch error:', error);
    });
} catch (error) {
    console.error('Error:', error);
}
@open1999
Copy link
Author

open1999 commented Sep 9, 2024

thanks for the response.

My problem is not the JS which works perfectly but that the JS which must be triggered in the automa script error management does not work if we are under Firefox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants