Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda