{"id":17431,"date":"2023-01-30T17:28:03","date_gmt":"2023-01-30T08:28:03","guid":{"rendered":"https:\/\/docs.c-bot.pro\/?p=17431"},"modified":"2025-05-30T18:13:03","modified_gmt":"2025-05-30T09:13:03","slug":"javascript","status":"publish","type":"post","link":"https:\/\/docs.c-bot.pro\/en\/user_guide\/bot\/b-bot_editer\/javascript\/","title":{"rendered":"Execute JavaScript"},"content":{"rendered":"\n<p><a href=\"https:\/\/docs.c-bot.pro\/en\/\"><i class=\"fas fa-book\"><\/i>&nbsp;Home<\/a> &gt; <a href=\"https:\/\/docs.c-bot.pro\/en\/user_guide\">User guide<\/a> &gt; <a href=\"https:\/\/docs.c-bot.pro\/en\/user_guide\/bot\/\">BOT<\/a> &gt; <a href=\"https:\/\/docs.c-bot.pro\/en\/user_guide\/bot\/b-bot_editer\/\">How to use the BOT editor<\/a> &gt; Execute JavaScript<\/p>\n\n\n\n<h2 id=\"outline__1\" class=\"wp-block-heading\">Add a task to execute JavaScript<\/h2>\n\n\n\n<p>Cloud BOT can execute arbitrary JavaScript in the automatic operation procedure.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-large page_main_img\"><img loading=\"lazy\" decoding=\"async\" width=\"555\" height=\"305\" src=\"https:\/\/docs.c-bot.pro\/wp-content\/uploads\/2022\/07\/bot_js_en_01.jpg\" alt=\"\" class=\"wp-image-10136\"\/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<ul class=\"wp-block-list\">\n<li>By clicking the \"Script\" button in the task, the JavaScript input window will open.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Enter any JavaScript and press the OK button, and the task to execute the entered JavaScript will be added.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n\n\n\n<h3 id=\"outline__1_1\" class=\"wp-block-heading\">Execute JavaScript in any frame<\/h3>\n\n\n\n<p>Use \u201cExecute script in this frame\u201d to run the script in the frame where the selected element exists.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"412\" src=\"https:\/\/docs.c-bot.pro\/wp-content\/uploads\/2025\/01\/img_script_any_frame_en-1024x412.png\" alt=\"\" class=\"wp-image-32110\"\/><\/figure>\n\n\n\n<p>You can change the frame by changing the target element. <a href=\"https:\/\/docs.c-bot.pro\/en\/user_guide\/bot\/b-bot_editer\/task_operation\/#outline__11\">Click here<\/a> to learn more about the target element.<\/p>\n\n\n\n<h2 id=\"outline__2\" class=\"wp-block-heading\">About JavaScript description and specifications<\/h2>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 id=\"outline__2_1\" class=\"wp-block-heading\">References to data in the BOT<\/h3>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"555\" height=\"305\" src=\"https:\/\/docs.c-bot.pro\/wp-content\/uploads\/2022\/07\/bot_js_en_02.jpg\" alt=\"\" class=\"wp-image-10137\"\/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>The value stored as data in BOT can be referenced by using $ {data name}.<\/p>\n\n\n\n<p>You can browse the data and insert it into the Script from the Data reference button.<\/p>\n<\/div>\n<\/div>\n\n\n\n<h3 id=\"outline__2_2\" class=\"wp-block-heading\">You can use jQuery($),Lodash(_).<\/h3>\n\n\n\n<p>*If you want to refer to jQuery or Lodash loaded by the page you are viewing, use window.$ and window._.<\/p>\n\n\n\n<h3 id=\"outline__2_3\" class=\"wp-block-heading\">Prohibited character strings<\/h3>\n\n\n\n<p>Scripts containing the following strings may not be executed. (case insensitive)<\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\"><strong>import , require , eval , cbot<\/strong><\/p>\n\n\n\n<h2 id=\"outline__3\" class=\"wp-block-heading\">Store JavaScript execution result in data<\/h2>\n\n\n\n<p>By selecting the storage destination data, the execution result of JavaScript can be stored in the data.<\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\"><strong>* The result of the last executed process in JavaScript is stored in the storage destination data.<\/strong><\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"256\" src=\"https:\/\/docs.c-bot.pro\/wp-content\/uploads\/2022\/07\/bot_js_en_03-1024x256.jpg\" alt=\"\" class=\"wp-image-10138\"\/><\/figure>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Select \"New data\" from the pull-down menu of the storage destination data.<\/li>\n\n\n\n<li>Select the type of data by selecting new data.<\/li>\n\n\n\n<li>Select the data type from the type pull-down. (*)<\/li>\n\n\n\n<li>Enter the data name and press OK.<\/li>\n<\/ol>\n\n\n\n<p><small>* When storing data, you can select the storage destination data from \"Text\" or \"Multiple text\".<\/small><\/p>\n\n\n\n<h4 id=\"outline__3_3_1\" class=\"wp-block-heading\">Cast rule<\/h4>\n\n\n\n<p>When storing JavaScript values in the data, the values are cast according to the cast rules.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 226px;\">\n<thead>\n<tr style=\"height: 38px;\">\n<th style=\"height: 40px; width: 29.1667%;\">JavaScript value<\/th>\n<th style=\"height: 40px; width: 50.119%;\">Destination storage data type<\/th>\n<th style=\"height: 40px; width: 20.5952%;\">Cast result<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"height: 38px;\">\n<td style=\"height: 38px; width: 29.1667%;\"><strong>123<\/strong><\/td>\n<td style=\"height: 38px; width: 50.119%;\">Text<\/td>\n<td style=\"height: 38px; width: 20.5952%;\">123<\/td>\n<\/tr>\n<tr style=\"height: 37px;\">\n<td style=\"height: 37px; width: 29.1667%;\"><strong>[1,2,3]<\/strong><\/td>\n<td style=\"height: 37px; width: 50.119%;\">Text<\/td>\n<td style=\"height: 37px; width: 20.5952%;\">1,2,3<\/td>\n<\/tr>\n<tr style=\"height: 37px;\">\n<td style=\"height: 37px; width: 29.1667%;\"><strong>\"123\"<\/strong><\/td>\n<td style=\"height: 37px; width: 50.119%;\">Text<\/td>\n<td style=\"height: 37px; width: 20.5952%;\">123<\/td>\n<\/tr>\n<tr style=\"height: 37px;\">\n<td style=\"height: 37px; width: 29.1667%;\"><strong>[\"1\",\"2\",\"3\"]<\/strong><\/td>\n<td style=\"height: 37px; width: 50.119%;\">Text<\/td>\n<td style=\"height: 37px; width: 20.5952%;\">1,2,3<\/td>\n<\/tr>\n<tr style=\"height: 37px;\">\n<td style=\"height: 37px; width: 29.1667%;\"><strong>[\"1\",\"2\",\"3\"]<\/strong><\/td>\n<td style=\"height: 37px; width: 50.119%;\">Multiple text<\/td>\n<td style=\"height: 37px; width: 20.5952%;\"><i class=\"fas fa-layer-group\"><\/i> 1,2,3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 id=\"outline__4\" class=\"wp-block-heading\">JavaScript utilization sample<\/h2>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Operation details<\/th><th>Script sample<\/th><\/tr><\/thead><tbody><tr><td><strong>Click a button<\/strong><\/td><td>document.querySelector('#selector').click()<\/td><\/tr><tr><td><strong>Enter in the input form<\/strong><\/td><td>document.querySelector('#selector').value = ${data name};<\/td><\/tr><tr><td><strong>Delete unnecessary characters<\/strong><br>(080-1234-5678 <i class=\"fas fa-angle-right\"><\/i> 08012345678)<\/td><td>const text = ${data name};<br>text.replace('-', '');<\/td><\/tr><tr><td><strong>Use a regular expression to remove in a pattern<\/strong><br>(2021\/11\/26 15:13 <i class=\"fas fa-angle-right\"><\/i> 2021\/11\/26)<\/td><td>const text = ${data name};<br>text.replace(\/\\s\\d{2}:\\d{2}\/, '');<\/td><\/tr><tr><td><strong>Use regular expressions to replace all characters<\/strong><br>(2021\/11\/26 <i class=\"fas fa-angle-right\"><\/i> 2021-11-26)<\/td><td>const text = ${data name};<br>text.replace(\/\\\/\/g, '-');<\/td><\/tr><tr><td><strong>Change the format using a regular expression<\/strong><br>(2021-11-26 <i class=\"fas fa-angle-right\"><\/i> 26th November 2021)<\/td><td>const text = ${data name};<br>text.replace(\/(\\d{4})-(\\d{2})-(\\d{2})\/, '$1yeas$2month$3date');<\/td><\/tr><tr><td><strong>Obtain the date of the previous day (UTC)<\/strong><\/td><td>const date = new Date();<br>date.setDate(date.getDate() - 1);<br>date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();<\/td><\/tr><tr><td><strong>Obtain the date of the previous day (JST)<\/strong><\/td><td>const utcDate = new Date();<br>const jstDate = new Date(utcDate.toLocaleString('ja-JP', { timeZone: 'Asia\/Tokyo' }));<br>jstDate.setDate(jstDate.getDate() - 1);<br>jstDate.getFullYear() + '-' + (jstDate.getMonth() + 1) + '-' + jstDate.getDate();<\/td><\/tr><tr><td><strong>Trigger the Enter key press event.<\/strong><\/td><td>const input = document.querySelector('#selecter');<br>const enterEvent = new KeyboardEvent('keydown', { keyCode: 13 });<br>input.dispatchEvent(enterEvent);<\/td><\/tr><tr><td><strong>Suppress alert display<\/strong><\/td><td>window.alert = function() { return true; };<\/td><\/tr><tr><td><strong>Suppress the display of the confirmation dialog so that OK is selected.<\/strong><\/td><td>window.confirm = function() { return true; };<\/td><\/tr><tr><td><strong>Convert the date type text box to text type one.<\/strong><\/td><td>document.querySelector('#selector').type = 'text';<\/td><\/tr><tr><td><strong>Raise an exception.<\/strong><\/td><td>throw new Error(\"error\");<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;Home &gt; User guide &gt; BOT &gt; How to use the BOT editor &gt; Execute JavaScript Add a task to execute JavaScript Cloud BOT can execute arbitrary JavaScript in the automatic operation procedure. Execute JavaScript in any frame Use \u201cExecute script in this frame\u201d to run the script in the frame where the selected element exists. You can change the frame by changing the target element. Click here to learn more about the target element. About JavaScript description and specifications References to data in the BOT The value stored as data in BOT can be referenced by using $ {data name}. You can browse the data and insert it into the Script from the Data reference button. You can use jQuery($),Lodash(_). *If you want to refer to jQuery or Lodash loaded by the page you are viewing, use window.$ and window._. Prohibited character strings Scripts containing the following strings may not be executed. (case insensitive) import , require , eval , cbot Store JavaScript execution result in data By selecting the storage destination data, the execution result of JavaScript can be stored in the data. * The result of the last executed process in JavaScript is stored in the storage [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_locale":"en_US","_original_post":"https:\/\/docs.c-bot.pro\/?p=10831","footnotes":""},"categories":[30],"tags":[54],"class_list":["post-17431","post","type-post","status-publish","format-standard","hentry","category-b-bot_editer","tag-bot","en-US"],"_links":{"self":[{"href":"https:\/\/docs.c-bot.pro\/wp-json\/wp\/v2\/posts\/17431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/docs.c-bot.pro\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.c-bot.pro\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.c-bot.pro\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.c-bot.pro\/wp-json\/wp\/v2\/comments?post=17431"}],"version-history":[{"count":10,"href":"https:\/\/docs.c-bot.pro\/wp-json\/wp\/v2\/posts\/17431\/revisions"}],"predecessor-version":[{"id":32869,"href":"https:\/\/docs.c-bot.pro\/wp-json\/wp\/v2\/posts\/17431\/revisions\/32869"}],"wp:attachment":[{"href":"https:\/\/docs.c-bot.pro\/wp-json\/wp\/v2\/media?parent=17431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.c-bot.pro\/wp-json\/wp\/v2\/categories?post=17431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.c-bot.pro\/wp-json\/wp\/v2\/tags?post=17431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}