html.js, which isn’t visible in your Gatsby project by default.
To expose (make available) the
html.js file, open your terminal, navigate to the root of your Gatsby project folder, and enter the following:
cp .cache/default-html.js src/html.js
html.js is available in your
src folder in your Gatsby project.
html.js file there’s a bunch of HTML syntax that you probably recognize. Don’t touch any of the existing code, but pay attention to the div element with an
dangerouslySetInnerHTML attribute. We need to use the same attribute, with the
Copy & paste the following snippet right above your
html.js file‘s closing body tag
Save your changes, and start your Gatsby server, or refresh your browser tab if Gatsby is already running. If you did it correctly, you should see the following message in your chrome console:
Try adding a click event with an alert message inside your script element: