Skip to content

Inject wixEmbedsAPI inline script into SSR responses - #36

Draft
guyofeck wants to merge 1 commit into
mainfrom
inject-wix-embeds-script
Draft

Inject wixEmbedsAPI inline script into SSR responses#36
guyofeck wants to merge 1 commit into
mainfrom
inject-wix-embeds-script

Conversation

@guyofeck

@guyofeck guyofeck commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

What

Adds an inline script to every server-rendered HTML page that defines window.wixEmbedsAPI.isWixSite:

<script>window.wixEmbedsAPI.isWixSite = () => true;</script>

How

Converts the single casing-normalization middleware in src/middleware.ts into an Astro sequence() and adds a final step (injectWixEmbedsScript) that:

  • Runs last in the middleware chain, so it only acts once all upstream middleware has finished and the page has been server-rendered.
  • Awaits next(), and for text/html responses rewrites the body to insert the script just before </body> (falling back to appending if there's no </body>).
  • Drops the content-length header so the runtime recomputes it for the rewritten body.

The script is placed at the end of <body> so Wix's own scripts have set up window.wixEmbedsAPI before the assignment runs.

Note: the original request wrote window.wixEmbedsAPI.isWixSite: () => true, but : is invalid statement syntax and would throw a SyntaxError in the browser, so it's injected as an assignment (=).

Verification

  • wix build succeeds.
  • Deployed via wix preview and fetched the live page — returns 200 text/html with the script present immediately before </body>.

🤖 Generated with Claude Code

Convert the single casing-normalization middleware into a sequence and
add a final step that injects an inline script into every server-rendered
HTML page. Running it last in the chain means it only acts once all
upstream middleware has finished and the page has been rendered.

The injected script defines window.wixEmbedsAPI.isWixSite, inserted just
before </body> so Wix's own scripts have set up wixEmbedsAPI first. The
content-length header is dropped so the runtime recomputes it for the
rewritten body.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant