I tried applying this using ChatGPT, but it didn't work for me. Can you tell me where to put this code to make my code work?
// Функция для эмуляции нажатия мыши внутри элемента <canvas data-sentry-element="Stage"> function simulateMouseClickInCanvas() { const canvas = document.querySelector('canvas[data-sentry-element="Stage"]'); if (!canvas) { console.error("Элемент <canvas> не найден."); return; } const rect = canvas.getBoundingClientRect(); // Выбираем случайные координаты внутри элемента <canvas> const randomX = Math.random() * rect.width + rect.left; const randomY = Math.random() * rect.height + rect.top; // Создаём события мыши const mouseDownEvent = new MouseEvent("mousedown", { bubbles: true, cancelable: true, clientX: randomX, clientY: randomY, }); const mouseUpEvent = new MouseEvent("mouseup", { bubbles: true, cancelable: true, clientX: randomX, clientY: randomY, }); const clickEvent = new MouseEvent("click", { bubbles: true, cancelable: true, clientX: randomX, clientY: randomY, }); // Эмулируем события canvas.dispatchEvent(mouseDownEvent); canvas.dispatchEvent(mouseUpEvent); canvas.dispatchEvent(clickEvent); } // Функция для выполнения кликов с рандомной задержкой function performRandomClicksInCanvas(maxClicks) { let clicksCount = 0; function clickWithRandomDelay() { if (clicksCount >= maxClicks) { console.log("Все клики выполнены"); return; } const delay = Math.random() * (2000 - 100) + 100; // Рандомная задержка от 0.1 до 2 секунд setTimeout(() => { simulateMouseClickInCanvas(); clicksCount++; console.log(`Клик ${clicksCount} выполнен (задержка: ${Math.round(delay)} мс)`); clickWithRandomDelay(); // Рекурсивный вызов для следующего клика }, delay); } clickWithRandomDelay(); } // Запуск выполнения 10 кликов performRandomClicksInCanvas(10);Node.js Mysql with Query from Variable how to get it working?
-
Hi,
i have the following problem.. i can use a variable to be used as a query, but it only works when i use the "current" file, not when i make an extra file like "mysql" in Node.js editor.
so this works:
File Current// get the client const mysql = require('mysql2'); // create the connection to database const connection = mysql.createConnection({ host: '10.10.10.1', user: 'aaaa', database: 'test1', password: 'aaaa' }); console.log("making request") var query = [[QUERY]]; await(new Promise((resolve, reject) => { connection.query( query, function (err, results, fields) { if(err) { reject(err) return } [[RESULTS]] = results resolve() } ); })); console.log([[RESULTS]]) connection.end(); console.log("ended connection")Output is:
Thread #1 : making request
Thread #1 : [{"COL1":1,"COL2":"abc","COL3":"def"}]
Thread #1 : ended connectionBut this works not:
File Current:
await require("../mysql")(); console.log("query done")File mysql:
module.exports = async function(){ // get the client const mysql = require('mysql2'); // create the connection to database const connection = mysql.createConnection({ host: '10.10.10.1', user: 'aaaa', database: 'test1', password: 'aaaa' }); console.log("making request") var query = [[QUERY]]; await(new Promise((resolve, reject) => { connection.query( query, function (err, results, fields) { if(err) { reject(err) return } [[RESULTS]] = results resolve() } ); })); console.log([[RESULTS]]) connection.end(); console.log("ended connection") }I get the error
Thread #1 : making request
Thread #1 : TypeError: Cannot read property 'constructor' of undefinedhow to get it done?
-
hmm for anybody with the same problem i did the following:
Make a new BAS function: mysql
put the node.js with the first code from above inside the function.now when i need to make a query i make a template with SELECT * FROM 'tableabcd' to var QUERY and then call the function mysql after this...
not a very clean solution but it works.. hmm :/
Please give Advice for a better solution!

-
@tecnewb said in Node.js Mysql with Query from Variable how to get it working?:
await(new Promise((resolve, reject) => {
I have found a solution that can keep the BAS variables in your extra files. Simply set a initial value to the BAS variables in the "Current" file before they are used in the extra files. Example: in your current file near the top add [[RESULTS]] = ''.
Once you set the BAS variable to any value in the "Current" file, you're able to get and set it in the extra files.
-
@jimhill21 said in Node.js Mysql with Query from Variable how to get it working?:
@tecnewb said in Node.js Mysql with Query from Variable how to get it working?:
await(new Promise((resolve, reject) => {
I have found a solution that can keep the BAS variables in your extra files. Simply set a initial value to the BAS variables in the "Current" file before they are used in the extra files. Example: in your current file near the top add [[RESULTS]] = ''.
Once you set the BAS variable to any value in the "Current" file, you're able to get and set it in the extra files.
@Support knows about this problem and will fix it in the next version. By setting any value in the "current" file for the BAS variable, you will get a bug in the "Run" mode:
current file
[[RESULT]] = "hello" await require("../bas.js")();
bas.js
module.exports = async function () { await BAS_API("VAR_RESULT = thread_number()"); return console.log([[RESULT]]) }result:

Test script