Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Error en Gatsby al agregar un script en el cuerpo

Cuando intento agregar un script en el cuerpo de Gatsby, agregué el siguiente código en el archivo llamado gatsby-ssr.js

 const React = require("react") exports.onRenderBody = ({ setPostBodyComponents }) => { setPostBodyComponents([ <script type="text/javascript"> {` (function() { var envolveChatWidgetScript = document.createElement('script'); envolveChatWidgetScript.setAttribute('data-wg-publisher', '222222'); envolveChatWidgetScript.setAttribute('data-wg-campaign', '333333'); envolveChatWidgetScript.setAttribute('src', 'https://widget.envolvetech.com/static/js/app.js'); envolveChatWidgetScript.setAttribute('data-identifier', 'my_identifier'); envolveChatWidgetScript.setAttribute('data-backend', 'https://bot-dot-envolvetech-001.appspot.com'); document.body.appendChild(envolveChatWidgetScript); })(); `} </script> ]); };

pero luego, de alguna manera, lo que realmente está en el marcado es esto

 <script type="text/javascript"> (function() { var envolveChatWidgetScript = document.createElement(&#x27;script&#x27;); envolveChatWidgetScript.setAttribute(&#x27;data-wg-publisher&#x27;, &#x27;222222&#x27;); envolveChatWidgetScript.setAttribute(&#x27;data-wg-campaign&#x27;, &#x27;3333333&#x27;); envolveChatWidgetScript.setAttribute(&#x27;src&#x27;, &#x27;https://widget.envolvetech.com/static/js/app.js&#x27;); envolveChatWidgetScript.setAttribute(&#x27;data-identifier&#x27;, &#x27;my_identifier#x27;); envolveChatWidgetScript.setAttribute(&#x27;data-backend&#x27;, &#x27;https://bot-dot-envolvetech-001.appspot.com&#x27;); document.body.appendChild(envolveChatWidgetScript); })(); </script>

¿Alguna idea de por qué se traduce a eso?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

¿Has intentado personalizar el html.js ?

Correr:

 cp .cache/default-html.js src/html.js

O copie manualmente el default-html.js (colocado dentro de .cache ) a /src

Y coloque su guión allí.

Cuando Gatsby construye su sitio si hay un html.js dentro de /src , lo usará como modelo para su sitio

En html.js, verá todos los postBodyComponents , onPreRenderHTML y otras API de personalización. Sin embargo, en este caso, insertará el script sin procesar en lugar de permitir que Gatsby lo analice.

about 4 years ago · Juan Pablo Isaza Report

0

Después de leer algunos hilos de GH, descubrí que agregar la secuencia de comandos usando DangerlySetInnerHTML realmente funciona https://github.com/gatsbyjs/gatsby/issues/11108

 const React = require("react") exports.onRenderBody = ({ setPostBodyComponents }) => { setPostBodyComponents([ <script dangerouslySetInnerHTML={{ __html:` (function() { var envolveChatWidgetScript = document.createElement("script"); envolveChatWidgetScript.setAttribute("data-wg-publisher", "222222"); envolveChatWidgetScript.setAttribute("data-wg-campaign", "333333"); envolveChatWidgetScript.setAttribute("src","https://widget.envolvetech.com/static/js/app.js"); envolveChatWidgetScript.setAttribute("data-identifier", "my_identifier"); envolveChatWidgetScript.setAttribute("data-backend", "https://bot-dot-envolvetech-001.appspot.com"); document.body.appendChild(envolveChatWidgetScript); })(); ` }} />, ]); };
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!