Skip to content

Fix Front script injection#1054

Open
dugjason wants to merge 3 commits intoGitbookIO:mainfrom
dugjason:fix-front-script-body-cedc4
Open

Fix Front script injection#1054
dugjason wants to merge 3 commits intoGitbookIO:mainfrom
dugjason:fix-front-script-body-cedc4

Conversation

@dugjason
Copy link

Fixes script injection issue.
The script now appends to the <body> element as recommended by Front, and a duplicate appendChild call has been removed.

Refer to Front docs https://help.front.com/en/articles/2049#install_front_chat_on_your_website

…e script now appends to the `<body>` element as recommended by Front, and a duplicate `appendChild` call has been removed.
@changeset-bot
Copy link

changeset-bot bot commented Nov 18, 2025

⚠️ No Changeset found

Latest commit: 1461580

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 18, 2025

Open in StackBlitz

bun add https://pkg.pr.new/GitbookIO/integrations/@gitbook/api@1054

commit: 1461580

@dugjason
Copy link
Author

dugjason commented Nov 18, 2025

👇 Not sure what I can do about that failing Check integrations check (looks like it wants 1Password access?)

@addisonschultz
Copy link
Collaborator

Hi @dugjason

Thanks for investigating this with us! And thanks for starting this PR. I’ve tested this out, but it’s still not working.

After debugging a little more, it looks like it’s coming from the color-scheme set from the actual front widget.

It’s currently injecting normal, which for some reason isn’t respecting the inherited color scheme set on the page.

It looks like updating it to light dark (allowing both color schemes to go through) fixes the problem. Is this something you’d be able to look at with your product team?

CleanShot.2025-11-18.at.18.18.17.mp4

@dugjason
Copy link
Author

Good find - thanks @addisonschultz
I'll share with our design engineers.

That being said - the way the chat widget is currently implemented (loading in the <head> rather than towards the bottom of <body>) can cause various other issues. I would still advise we implement this if we can (unsure what to do about that failing CI check)

@addisonschultz
Copy link
Collaborator

@dugjason yes - thanks again for making this PR to fix the script injection. The 1password check is an ongoing issue we have from external PRs, I’ve verified the changes are valid and it’s good to go since the other checks are passing.

I will leave this PR open for now, in case we have a resolution from the product team soon? If we need to make any additional changes here?

@dugjason
Copy link
Author

Thanks Addison - sounds like a plan. We'll get back to you as we have news

@addisonschultz
Copy link
Collaborator

Hi @dugjason - do you have any updates for us?

@dugjason
Copy link
Author

dugjason commented Jan 7, 2026

Hey @addisonschultz , I think it's resolved 🤞
Do you have a Gitbook instance w/Front Chat enabled we can review it on?

@addisonschultz
Copy link
Collaborator

Hi @dugjason - It does look like it’s fixed!

https://support.backpack.exchange/

Just to clarify, this was something you updated on the Front script side, right?

@addisonschultz
Copy link
Collaborator

@dugjason actually - apologies, backpack is still running into the issue. I’m doing some more testing on my end too:

image

@addisonschultz
Copy link
Collaborator

@dugjason any update? 🙏

We’d love to get this resolved for Backpack if possible

@sammassey-bp
Copy link

sammassey-bp commented Jan 29, 2026

Hey @addisonschultz @dugjason,

We've been waiting on this fix for a while and wanted to help unblock it. Since the color-scheme issue is in Front's chat.bundle.js and getting that updated seems to be taking a while, here's a client-side workaround that can be added to this PR:

((d, s) => {
    const chatId = '<TO_REPLACE>';

    d = document;
    s = d.createElement('script');
    s.src = 'https://chat-assets.frontapp.com/v1/chat.bundle.js';
    s.async = 1;

    s.onload = () => {
        if (window.FrontChat) {
            window.FrontChat('init', { chatId: chatId, useDefaultLauncher: true });
        }

        // Workaround for Front's color-scheme bug
        // Front's widget uses color-scheme: normal which doesn't respect page color schemes
        // This override allows proper light/dark mode support
        const styleOverride = d.createElement('style');
        styleOverride.textContent = `
            [data-front-chat-container],
            [data-front-chat-container] iframe,
            #front-chat-container,
            #front-chat-container iframe {
                color-scheme: light dark !important;
            }
        `;
        d.head.appendChild(styleOverride);
    };

    // Append to body (just before closing </body> tag) as per Front's documentation
    d.getElementsByTagName('body')[0].appendChild(s);
})(window, document);

This injects a CSS override after the widget loads, forcing color-scheme: light dark which allows proper dark mode support without waiting for Front to update their bundle.

I've also filed an issue on the Front SDK repo to track the upstream fix: frontapp/front-chat-sdk#32

Happy to submit a PR with this change if that would be helpful!

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.

3 participants