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);HTTP requests with javascript/npm
-
Hello guys,
is there a way to make http requests via code execution and if so how?
When I try something in BAS it always gives a parse or syntax error.At the end I would like to make a request like this:
var filePath = [[FILE_PATH]]; var uploadUrl = [[URL]]; HTTPClient.Request({ url: uploadUrl, method: 'PUT', headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0', 'Accept': 'application/xml, text/xml, */*; q=0.01', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate, br', 'Content-Type': 'application/octet-stream', 'Content-Length': [[CONTENT_LENGTH]], 'Referer': 'https://xxx.com/', 'x-amz-server-side-encryption': 'AES256', 'x-amz-acl': 'private', 'Content-Disposition': 'attachment;filename="' + [[FILE_NAME]] + '"; filename*=utf-8\'\'' + [[FILE_NAME]], 'x-amz-storage-class': 'STANDARD', 'x-amz-meta-user-id': [[AMZ_UID]], 'Origin': 'https://xxx.com' }, body: File.ReadBinary(filePath), success: function(response) { Log(response.body); }, fail: function(response) { Log('Error on upload: ' + response.body); } });Thank you for helping
-
@basmail said in HTTP requests with javascript/npm:
Hello guys,
is there a way to make http requests via code execution and if so how?
When I try something in BAS it always gives a parse or syntax error.At the end I would like to make a request like this:
Thank you for helping
You can't send a request via "Execute code" via js like you can via the browser console. Use node js
-
-
@basmail said in HTTP requests with javascript/npm:
@Fox said in HTTP requests with javascript/npm:
You can't send a request via "Execute code" via js like you can via the browser console. Use node js
Ok, how is it done in this complex structure? There is not even a log when something fails
Use node js
-
@basmail said in HTTP requests with javascript/npm:
@Fox said in HTTP requests with javascript/npm:
Use node js
Yes I got that, but how is it done in node.js with this complex structure? There is not even a log when something fails...
Have you tried searching the forum for topics where users discussed sending requests from node js?