{"id":413673,"date":"2024-06-29T23:16:09","date_gmt":"2024-06-29T23:16:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=413673"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=413673","title":{"rendered":"<span>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c config \u0434\u043b\u044f web js \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a\u0430\u043a \u0442\u043e \u0440\u0430\u0437 \u043c\u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c &#171;Contact us&#187; \u0432\u0438\u0434\u0436\u0435\u0442 \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0434\u0438\u043b\u0435\u043c\u043c\u0430, <strong>\u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043a\u043d\u043e\u043f\u043a\u0438?<\/strong> <\/p>\n<p>\u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0447\u0442\u043e\u0431\u044b:<\/p>\n<ul>\n<li>\n<p>\u0412\u0441\u0451 \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0434\u043b\u044f \u043d\u0435(<s>\u0434\u043e<\/s>)\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u041b\u0435\u0433\u043a\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0441\u0440\u0430\u0437\u0443 \u0436\u0435<\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p>\u0412\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0441\u0440\u0430\u0437\u0443 \u0436\u0435<\/p>\n<\/blockquote>\n<p>\u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0432\u0432\u0438\u0434\u0443 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442. \u0411\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0432\u044b\u0437\u043e\u0432\u0430 \u0433\u0434\u0435-\u0442\u043e \u0442\u0430\u043c \u0432 \u043a\u043e\u0434\u0435. <strong>\u041c\u043d\u0435 \u0440\u0430\u0437\u0443 \u0436\u0435 \u043f\u0440\u0438\u0448\u043b\u0430 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u0438\u0434\u0435\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 GET \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 URL<\/strong>. <\/p>\n<p>\u041d\u043e \u0442\u0430\u043a\u0436\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0432\u044b\u043b\u043e\u0436\u0438\u0442\u044c \u043a\u043e\u0434 \u043d\u0430 github \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438&#8230; \u042f \u0437\u0430\u0434\u0430\u043b <a href=\"https:\/\/qna.habr.com\/q\/1040676\" rel=\"noopener noreferrer nofollow\">\u0432\u043e\u043f\u0440\u043e\u0441<\/a> \u043d\u0430 <s>Toster<\/s> QNA Habr<\/p>\n<blockquote>\n<p><strong>\u041a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c GET \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441\u0441\u044b\u043b\u043a\u0438 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u044b\u043b \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d \u0441\u043a\u0440\u0438\u043f\u0442?<\/strong>  \u0427\u0442\u043e \u044f \u0438\u043c\u0435\u044e \u0432 \u0432\u0438\u0434\u0443 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0441\u043a\u0440\u0438\u043f\u0442 \u0437\u0430\u043b\u0438\u0442\u044b\u0439 \u043d\u0430 github htt\u0440s;\/\/m\u0443sit\u0435.github.i\u043e\/script.js    \u041d\u0430 \u0441\u0430\u0439\u0442\u0435 example.com \u043c\u044b \u0435\u0433\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c  <code>&lt;script defer src=\"https:\/\/mysite.github.io\/script.js?param1=1&amp;param2=2\">&lt;\/script>  &lt;!-- \u0432 \u0441\u0441\u044b\u043b\u043a\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b --><\/code>    <em>Github \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0447\u0442\u043e \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0435.<\/em>  <strong>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0438\u0437 js \u0443\u0437\u043d\u0430\u0442\u044c \u0438\u0437 \u043a\u0430\u043a\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 script \u043e\u043d \u0431\u044b\u043b \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d? \u0418\u043b\u0438 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438\u0437 URL?<\/strong><\/p>\n<\/blockquote>\n<p>\u041d\u043e \u043f\u043e\u0441\u043b\u0435 5 \u043c\u0438\u043d\u0443\u0442 \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u044f \u043d\u0430\u0448\u0435\u043b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Document\/currentScript\" rel=\"noopener noreferrer nofollow\">\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e<\/a> \u043e\u0431\u044a\u0435\u043a\u0442\u0430 document. <code>document.currentScript<\/code>  <\/p>\n<h2>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438\u0437 \u0430\u0434\u0440\u0435\u0441\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/h2>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0434\u0435\u043b\u043e \u0437\u0430 \u043c\u0430\u043b\u044b\u043c, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443, \u043f\u0430\u0440\u0441\u0438\u043c \u0438 \u0440\u0430\u0434\u0443\u0435\u043c\u0441\u044f \u0447\u0442\u043e \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0438\u0441\u0430\u0442\u044c backend \u043b\u043e\u0433\u0438\u043a\u0443<\/p>\n<pre><code class=\"xml\"> &lt;head>    ...    &lt;script defer src=\"https:\/\/mysite.github.io\/script.js?color=fff&amp;text=helloWorld\">&lt;\/script> &lt;\/head><\/code><\/pre>\n<pre><code class=\"javascript\">let selfElement = document.currentScript;  if (selfElement?.src) {   let urlR = selfElement.src,   url = new URL(urlR), params = url.searchParams  if (params.has(\"color\")) {     mycustomelement.setColor(params.get(\"color\"))   }  if (params.has(\"text\")) {   mycustomelement.setText(params.get(\"text\"))   } ...  }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0443\u0441\u043f\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u0430\u043b\u044c\u0448\u0435&#8230; \u041d\u041e \u043c\u0435\u043d\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0430 \u043e\u0434\u043d\u0430 \u0448\u0442\u0443\u043a\u0430. \u0410 \u0442\u043e\u0447\u043d\u0435\u0435 \u0442\u0435\u0433 <code>&lt;script><\/code> \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>src<\/code> \u0442\u043e \u044d\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f. \u041d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0443\u0436\u0435 \u0441\u043c\u043e\u0433\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u043d\u0435\u0434\u043e\u0440\u0430\u0437\u0443\u043c\u0435\u043d\u0438\u0435<\/p>\n<pre><code class=\"javascript\">eval(selfElement.innerText);<\/code><\/pre>\n<h2>\u041d\u043e\u0432\u0430\u044f \u044d\u0440\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u043e\u0432<\/h2>\n<p>\u0418 \u0442\u0443\u0442 \u043c\u0435\u043d\u044f \u043e\u0441\u0435\u043d\u0438\u043b\u043e \u043c\u043e\u0436\u043d\u043e \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043f\u043b\u0430\u0433\u0438\u043d\u0430<\/p>\n<pre><code class=\"xml\">&lt;head>   ...   &lt;script defer src=\"https:\/\/mysite.github.io\/script.js\">     {       \"color\":\"#fff\",       \"text\":\"Hello world!\"    }   &lt;\/script> &lt;\/head><\/code><\/pre>\n<p>\u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0451 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e<\/p>\n<pre><code class=\"javascript\">let config = JSON.parse(selfElement.innerText);<\/code><\/pre>\n<p>\u0412\u0441\u0451 \u0431\u044b \u0431\u044b\u043b\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0435\u0441\u043b\u0438 \u0431\u044b VScode \u043d\u0435 \u0440\u0443\u0433\u0430\u043b\u0441\u044f \u043d\u0430 JSON \u043c\u0435\u0436\u0434\u0443 \u0442\u0435\u0433\u043e\u0432 <code>script<\/code> \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u044d\u0442\u043e \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e, \u043d\u043e \u043c\u043d\u0435 \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043b\u0435\u0441\u0442\u044c \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u043e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u043e\u0441\u044c. \u0411\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b IDE \u0434\u0443\u043c\u0430\u043b\u043e \u0447\u0442\u043e \u044d\u0442\u043e javascript<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0431\u044b \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u0432\u044b\u0447\u043a\u0438 \u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043a\u043e\u0439 \u043f\u0430\u0440\u0441\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438. \u041d\u043e \u044d\u0442\u043e \u0443\u0436\u0430\u0441\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a<\/p>\n<pre><code class=\"xml\">&lt;head>    ...    &lt;script defer src=\"https:\/\/mysite.github.io\/script.js\">   return {     color: \"#fff\",       text: \"Hello JS world!\",     }   &lt;\/script> &lt;\/head><\/code><\/pre>\n<p>\u0414\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c js \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u0433\u0430 <code>script<\/code> \u043a\u0442\u043e \u0431\u044b \u043c\u043e\u0433 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c) \u0420\u0435\u0448\u0438\u043b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>eval<\/code> \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/eval#never_use_eval!\" rel=\"noopener noreferrer nofollow\">\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e<\/a><\/p>\n<pre><code class=\"javascript\">let config = new Function(selfElement.innerText)();<\/code><\/pre>\n<p>\u0421\u0443\u043f\u0435\u0440 \u043c\u044b \u0432 \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u0435?! \u041d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c( \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043c\u0438\u043c\u043e \u043d\u0430\u0448\u0435\u0433\u043e <code>return<\/code> \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 js \u043a\u043e\u0434, \u044d\u0442\u043e \u043d\u0438\u043a\u0443\u0434\u0430 \u043d\u0435 \u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f&#8230; \u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c? \u0412 \u0433\u043e\u043b\u043e\u0432\u0443 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 SandBox. \u041d\u043e \u043a\u0430\u043a \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c js \u043a\u043e\u0434 \u0432 js? \u0416\u0435\u043b\u0430\u043d\u0438\u044f \u0442\u044f\u043d\u0443\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0435\u0442, \u043d\u0430\u0434\u043e \u043d\u0430\u0439\u0442\u0438 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0447\u0430\u0441\u0430 \u043f\u043e\u0438\u0441\u043a\u043e\u0432 \u043d\u0430\u0448\u0451\u043b\u0441\u044f \u043e\u0434\u0438\u043d <a href=\"https:\/\/gist.github.com\/alejandrolechuga\/9381781\" rel=\"noopener noreferrer nofollow\">gist<\/a><\/p>\n<pre><code class=\"javascript\">function construct(constructor, args) {   function F() {       return constructor.apply(this, args);   }   F.prototype = constructor.prototype;   return new F(); } \/\/ Sanboxer  function sandboxcode(string, inject) {   \"use strict\";   var globals = [\"Function\"];   for (var i in window) {     \/\/ &lt;--REMOVE THIS CONDITION     if (i != \"console\")     \/\/ REMOVE THIS CONDITION -->     globals.push(i);   }   \/\/ The strict mode prevents access to the global object through an anonymous function (function(){return this;}()));   globals.push('\"use strict\";\\n'+string);   return construct(Function, globals).apply(inject ? inject : {}); } sandboxcode('console.log( this, window, top , self, parent, this[\"jQuery\"], (function(){return this;}()));');  \/\/ => Object {} undefined undefined undefined undefined undefined undefined  sandboxcode('return this;', {window:\"sanboxed code\"});  \/\/ => Object {window: \"sanboxed code\"}<\/code><\/pre>\n<p>\u041c\u043d\u0435 \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043a\u0430\u043a \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u044f\u0441\u043d\u044e. \u041c\u044b \u0432\u0438\u0434\u0438\u043c 2 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>construct<\/code> \u0438 <code>sandboxcode<\/code> \u041f\u0435\u0440\u0432\u0430\u044f \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u043e\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>F<\/code> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u0441\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f, \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u043a\u0443\u0447\u0435\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<pre><code class=\"javascript\">function anonymous(top,window,location,external,chrome,document,...) {  \"use strict\";  return this; }<\/code><\/pre>\n<p><strong>\u0412 \u044d\u0442\u043e\u043c \u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u044f \u043c\u0430\u0433\u0438\u044f \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/strong>.<\/p>\n<p>\u041d\u043e \u043a\u043e\u0434 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0436\u043a\u043e \u043f\u043e\u0434\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u0432\u0441\u0435 \u0436\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0432\u043e \u0432\u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>eval();<\/code> \u0438\u043b\u0438 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/globalThis\" rel=\"noopener noreferrer nofollow\">globalThis <\/a><\/p>\n<pre><code class=\"javascript\">\/\/https:\/\/gist.github.com\/gornostay25\/3ea24d743c90b2cd6b2aaadb9241fec9 function sandboxcode(s) {     function construct(c, a) {         function F(){return c.apply(this, a)}         F.prototype = c.prototype;         return new F()     }     let g = [\"Function\",\"globalThis\",\"eval\"]     for (let i in globalThis){g.push(i)}     g.push(s);     return construct(Function, g).apply({}); }<\/code><\/pre>\n<p>\u042f \u0443\u0431\u0440\u0430\u043b \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0441\u0432\u043e\u0438\u0445 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u043c\u043d\u0435 \u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0443\u0436\u043d\u043e, \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u043a\u043e\u0440\u043e\u0442\u0438\u043b \u043a\u043e\u0434. \u0412 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 <code>g<\/code> \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"javascript\">\/\/function F(){return c.apply(this, a)} Function.apply({},[\"test\",\"ttest\",\"ttest2\",\"alert(123);\"]) \/* \u0192 anonymous(test,ttest,ttest2 ) { alert(123); } *\/<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u043c\u0435\u043d\u0442 \u0438\u0441\u0442\u0438\u043d\u044b:<\/p>\n<pre><code class=\"xml\">&lt;head>   ...   &lt;script defer src=\"https:\/\/mysite.github.io\/script.js\">     alert(\"bad code\"); \/\/Uncaught TypeError: alert is not a function     console.log(window,this,globalThis,Function,eval);     \/\/ => undefined {} undefined undefined undefined     return {       color: \"#fff\",       text: \"Hello JS world!\",     }   &lt;\/script> &lt;\/head><\/code><\/pre>\n<pre><code class=\"javascript\">let config = JSON.parse(JSON.stringify(sandboxcode(selfElement.innerText))); \/\/ => {color: \"#fff\", text: \"Hello JS world!\"}<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043a\u0430\u043a\u0438\u043c \u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0430\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u043b\u0438 \u0433\u0435\u0442\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u0430, \u0434\u0435\u043b\u0430\u0435\u043c \u0444\u0438\u043b\u044c\u0442\u0440 \u0447\u0435\u0440\u0435\u0437 <code>JSON<\/code> <strong>\u0418 \u0432\u0441\u0451, \u043c\u044b \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0438\u0441\u044c!!!<\/strong> <\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f. \u041c\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u044f\u0442\u043d\u043e, \u0433\u0443\u043b\u044f\u044f \u043f\u043e github \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0447\u0442\u043e \u043a\u0442\u043e-\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b \u0441\u0432\u043e\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0438\u043b\u0438 \u0432\u0438\u0434\u0436\u0435\u0442 \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443. \u0412\u0441\u0435\u043c \u0432\u0441\u0435\u0433\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/576356\/\"> https:\/\/habr.com\/ru\/articles\/576356\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a\u0430\u043a \u0442\u043e \u0440\u0430\u0437 \u043c\u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c &#171;Contact us&#187; \u0432\u0438\u0434\u0436\u0435\u0442 \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0434\u0438\u043b\u0435\u043c\u043c\u0430, <strong>\u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043a\u043d\u043e\u043f\u043a\u0438?<\/strong> <\/p>\n<p>\u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0447\u0442\u043e\u0431\u044b:<\/p>\n<ul>\n<li>\n<p>\u0412\u0441\u0451 \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0434\u043b\u044f \u043d\u0435(<s>\u0434\u043e<\/s>)\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u041b\u0435\u0433\u043a\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0441\u0440\u0430\u0437\u0443 \u0436\u0435<\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p>\u0412\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0441\u0440\u0430\u0437\u0443 \u0436\u0435<\/p>\n<\/blockquote>\n<p>\u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0432\u0432\u0438\u0434\u0443 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442. \u0411\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0432\u044b\u0437\u043e\u0432\u0430 \u0433\u0434\u0435-\u0442\u043e \u0442\u0430\u043c \u0432 \u043a\u043e\u0434\u0435. <strong>\u041c\u043d\u0435 \u0440\u0430\u0437\u0443 \u0436\u0435 \u043f\u0440\u0438\u0448\u043b\u0430 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u0438\u0434\u0435\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 GET \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 URL<\/strong>. <\/p>\n<p>\u041d\u043e \u0442\u0430\u043a\u0436\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0432\u044b\u043b\u043e\u0436\u0438\u0442\u044c \u043a\u043e\u0434 \u043d\u0430 github \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438&#8230; \u042f \u0437\u0430\u0434\u0430\u043b <a href=\"https:\/\/qna.habr.com\/q\/1040676\" rel=\"noopener noreferrer nofollow\">\u0432\u043e\u043f\u0440\u043e\u0441<\/a> \u043d\u0430 <s>Toster<\/s> QNA Habr<\/p>\n<blockquote>\n<p><strong>\u041a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c GET \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441\u0441\u044b\u043b\u043a\u0438 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u044b\u043b \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d \u0441\u043a\u0440\u0438\u043f\u0442?<\/strong>  \u0427\u0442\u043e \u044f \u0438\u043c\u0435\u044e \u0432 \u0432\u0438\u0434\u0443 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0441\u043a\u0440\u0438\u043f\u0442 \u0437\u0430\u043b\u0438\u0442\u044b\u0439 \u043d\u0430 github htt\u0440s;\/\/m\u0443sit\u0435.github.i\u043e\/script.js    \u041d\u0430 \u0441\u0430\u0439\u0442\u0435 example.com \u043c\u044b \u0435\u0433\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c  <code>&lt;script defer src=\"https:\/\/mysite.github.io\/script.js?param1=1&amp;param2=2\">&lt;\/script>  &lt;!-- \u0432 \u0441\u0441\u044b\u043b\u043a\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b --><\/code>    <em>Github \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0447\u0442\u043e \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0435.<\/em>  <strong>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0438\u0437 js \u0443\u0437\u043d\u0430\u0442\u044c \u0438\u0437 \u043a\u0430\u043a\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 script \u043e\u043d \u0431\u044b\u043b \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d? \u0418\u043b\u0438 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438\u0437 URL?<\/strong><\/p>\n<\/blockquote>\n<p>\u041d\u043e \u043f\u043e\u0441\u043b\u0435 5 \u043c\u0438\u043d\u0443\u0442 \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u044f \u043d\u0430\u0448\u0435\u043b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Document\/currentScript\" rel=\"noopener noreferrer nofollow\">\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e<\/a> \u043e\u0431\u044a\u0435\u043a\u0442\u0430 document. <code>document.currentScript<\/code>  <\/p>\n<h2>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438\u0437 \u0430\u0434\u0440\u0435\u0441\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/h2>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0434\u0435\u043b\u043e \u0437\u0430 \u043c\u0430\u043b\u044b\u043c, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443, \u043f\u0430\u0440\u0441\u0438\u043c \u0438 \u0440\u0430\u0434\u0443\u0435\u043c\u0441\u044f \u0447\u0442\u043e \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0438\u0441\u0430\u0442\u044c backend \u043b\u043e\u0433\u0438\u043a\u0443<\/p>\n<pre><code class=\"xml\"> &lt;head>    ...    &lt;script defer src=\"https:\/\/mysite.github.io\/script.js?color=fff&amp;text=helloWorld\">&lt;\/script> &lt;\/head><\/code><\/pre>\n<pre><code class=\"javascript\">let selfElement = document.currentScript;  if (selfElement?.src) {   let urlR = selfElement.src,   url = new URL(urlR), params = url.searchParams  if (params.has(\"color\")) {     mycustomelement.setColor(params.get(\"color\"))   }  if (params.has(\"text\")) {   mycustomelement.setText(params.get(\"text\"))   } ...  }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0443\u0441\u043f\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u0430\u043b\u044c\u0448\u0435&#8230; \u041d\u041e \u043c\u0435\u043d\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0430 \u043e\u0434\u043d\u0430 \u0448\u0442\u0443\u043a\u0430. \u0410 \u0442\u043e\u0447\u043d\u0435\u0435 \u0442\u0435\u0433 <code>&lt;script><\/code> \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>src<\/code> \u0442\u043e \u044d\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f. \u041d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0443\u0436\u0435 \u0441\u043c\u043e\u0433\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u043d\u0435\u0434\u043e\u0440\u0430\u0437\u0443\u043c\u0435\u043d\u0438\u0435<\/p>\n<pre><code class=\"javascript\">eval(selfElement.innerText);<\/code><\/pre>\n<h2>\u041d\u043e\u0432\u0430\u044f \u044d\u0440\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u043e\u0432<\/h2>\n<p>\u0418 \u0442\u0443\u0442 \u043c\u0435\u043d\u044f \u043e\u0441\u0435\u043d\u0438\u043b\u043e \u043c\u043e\u0436\u043d\u043e \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043f\u043b\u0430\u0433\u0438\u043d\u0430<\/p>\n<pre><code class=\"xml\">&lt;head>   ...   &lt;script defer src=\"https:\/\/mysite.github.io\/script.js\">     {       \"color\":\"#fff\",       \"text\":\"Hello world!\"    }   &lt;\/script> &lt;\/head><\/code><\/pre>\n<p>\u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0451 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e<\/p>\n<pre><code class=\"javascript\">let config = JSON.parse(selfElement.innerText);<\/code><\/pre>\n<p>\u0412\u0441\u0451 \u0431\u044b \u0431\u044b\u043b\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0435\u0441\u043b\u0438 \u0431\u044b VScode \u043d\u0435 \u0440\u0443\u0433\u0430\u043b\u0441\u044f \u043d\u0430 JSON \u043c\u0435\u0436\u0434\u0443 \u0442\u0435\u0433\u043e\u0432 <code>script<\/code> \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u044d\u0442\u043e \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e, \u043d\u043e \u043c\u043d\u0435 \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043b\u0435\u0441\u0442\u044c \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u043e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u043e\u0441\u044c. \u0411\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b IDE \u0434\u0443\u043c\u0430\u043b\u043e \u0447\u0442\u043e \u044d\u0442\u043e javascript<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0431\u044b \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u0432\u044b\u0447\u043a\u0438 \u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043a\u043e\u0439 \u043f\u0430\u0440\u0441\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438. \u041d\u043e \u044d\u0442\u043e \u0443\u0436\u0430\u0441\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a<\/p>\n<pre><code class=\"xml\">&lt;head>    ...    &lt;script defer src=\"https:\/\/mysite.github.io\/script.js\">   return {     color: \"#fff\",       text: \"Hello JS world!\",     }   &lt;\/script> &lt;\/head><\/code><\/pre>\n<p>\u0414\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c js \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u0433\u0430 <code>script<\/code> \u043a\u0442\u043e \u0431\u044b \u043c\u043e\u0433 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c) \u0420\u0435\u0448\u0438\u043b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>eval<\/code> \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/eval#never_use_eval!\" rel=\"noopener noreferrer nofollow\">\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e<\/a><\/p>\n<pre><code class=\"javascript\">let config = new Function(selfElement.innerText)();<\/code><\/pre>\n<p>\u0421\u0443\u043f\u0435\u0440 \u043c\u044b \u0432 \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u0435?! \u041d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c( \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043c\u0438\u043c\u043e \u043d\u0430\u0448\u0435\u0433\u043e <code>return<\/code> \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 js \u043a\u043e\u0434, \u044d\u0442\u043e \u043d\u0438\u043a\u0443\u0434\u0430 \u043d\u0435 \u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f&#8230; \u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c? \u0412 \u0433\u043e\u043b\u043e\u0432\u0443 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 SandBox. \u041d\u043e \u043a\u0430\u043a \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c js \u043a\u043e\u0434 \u0432 js? \u0416\u0435\u043b\u0430\u043d\u0438\u044f \u0442\u044f\u043d\u0443\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0435\u0442, \u043d\u0430\u0434\u043e \u043d\u0430\u0439\u0442\u0438 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0447\u0430\u0441\u0430 \u043f\u043e\u0438\u0441\u043a\u043e\u0432 \u043d\u0430\u0448\u0451\u043b\u0441\u044f \u043e\u0434\u0438\u043d <a href=\"https:\/\/gist.github.com\/alejandrolechuga\/9381781\" rel=\"noopener noreferrer nofollow\">gist<\/a><\/p>\n<pre><code class=\"javascript\">function construct(constructor, args) {   function F() {       return constructor.apply(this, args);   }   F.prototype = constructor.prototype;   return new F(); } \/\/ Sanboxer  function sandboxcode(string, inject) {   \"use strict\";   var globals = [\"Function\"];   for (var i in window) {     \/\/ &lt;--REMOVE THIS CONDITION     if (i != \"console\")     \/\/ REMOVE THIS CONDITION -->     globals.push(i);   }   \/\/ The strict mode prevents access to the global object through an anonymous function (function(){return this;}()));   globals.push('\"use strict\";\\n'+string);   return construct(Function, globals).apply(inject ? inject : {}); } sandboxcode('console.log( this, window, top , self, parent, this[\"jQuery\"], (function(){return this;}()));');  \/\/ => Object {} undefined undefined undefined undefined undefined undefined  sandboxcode('return this;', {window:\"sanboxed code\"});  \/\/ => Object {window: \"sanboxed code\"}<\/code><\/pre>\n<p>\u041c\u043d\u0435 \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043a\u0430\u043a \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u044f\u0441\u043d\u044e. \u041c\u044b \u0432\u0438\u0434\u0438\u043c 2 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>construct<\/code> \u0438 <code>sandboxcode<\/code> \u041f\u0435\u0440\u0432\u0430\u044f \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u043e\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>F<\/code> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u0441\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f, \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u043a\u0443\u0447\u0435\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<pre><code class=\"javascript\">function anonymous(top,window,location,external,chrome,document,...) {  \"use strict\";  return this; }<\/code><\/pre>\n<p><strong>\u0412 \u044d\u0442\u043e\u043c \u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u044f \u043c\u0430\u0433\u0438\u044f \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/strong>.<\/p>\n<p>\u041d\u043e \u043a\u043e\u0434 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0436\u043a\u043e \u043f\u043e\u0434\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u0432\u0441\u0435 \u0436\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0432\u043e \u0432\u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>eval();<\/code> \u0438\u043b\u0438 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/globalThis\" rel=\"noopener noreferrer nofollow\">globalThis <\/a><\/p>\n<pre><code class=\"javascript\">\/\/https:\/\/gist.github.com\/gornostay25\/3ea24d743c90b2cd6b2aaadb9241fec9 function sandboxcode(s) {     function construct(c, a) {         function F(){return c.apply(this, a)}         F.prototype = c.prototype;         return new F()     }     let g = [\"Function\",\"globalThis\",\"eval\"]     for (let i in globalThis){g.push(i)}     g.push(s);     return construct(Function, g).apply({}); }<\/code><\/pre>\n<p>\u042f \u0443\u0431\u0440\u0430\u043b \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0441\u0432\u043e\u0438\u0445 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u043c\u043d\u0435 \u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0443\u0436\u043d\u043e, \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u043a\u043e\u0440\u043e\u0442\u0438\u043b \u043a\u043e\u0434. \u0412 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 <code>g<\/code> \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"javascript\">\/\/function F(){return c.apply(this, a)} Function.apply({},[\"test\",\"ttest\",\"ttest2\",\"alert(123);\"]) \/* \u0192 anonymous(test,ttest,ttest2 ) { alert(123); } *\/<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u043c\u0435\u043d\u0442 \u0438\u0441\u0442\u0438\u043d\u044b:<\/p>\n<pre><code class=\"xml\">&lt;head>   ...   &lt;script defer src=\"https:\/\/mysite.github.io\/script.js\">     alert(\"bad code\"); \/\/Uncaught TypeError: alert is not a function     console.log(window,this,globalThis,Function,eval);     \/\/ => undefined {} undefined undefined undefined     return {       color: \"#fff\",       text: \"Hello JS world!\",     }   &lt;\/script> &lt;\/head><\/code><\/pre>\n<pre><code class=\"javascript\">let config = JSON.parse(JSON.stringify(sandboxcode(selfElement.innerText))); \/\/ => {color: \"#fff\", text: \"Hello JS world!\"}<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043a\u0430\u043a\u0438\u043c \u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0430\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u043b\u0438 \u0433\u0435\u0442\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u0430, \u0434\u0435\u043b\u0430\u0435\u043c \u0444\u0438\u043b\u044c\u0442\u0440 \u0447\u0435\u0440\u0435\u0437 <code>JSON<\/code> <strong>\u0418 \u0432\u0441\u0451, \u043c\u044b \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0438\u0441\u044c!!!<\/strong> <\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f. \u041c\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u044f\u0442\u043d\u043e, \u0433\u0443\u043b\u044f\u044f \u043f\u043e github \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0447\u0442\u043e \u043a\u0442\u043e-\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b \u0441\u0432\u043e\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0438\u043b\u0438 \u0432\u0438\u0434\u0436\u0435\u0442 \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443. \u0412\u0441\u0435\u043c \u0432\u0441\u0435\u0433\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/576356\/\"> https:\/\/habr.com\/ru\/articles\/576356\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-413673","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/413673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=413673"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/413673\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=413673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=413673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=413673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}