Skip to content

Commit d77b2c4

Browse files
Add css targeting to force apply light dark mode
1 parent 76e1a39 commit d77b2c4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

.changeset/cold-clocks-tan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/integration-front': minor
3+
---
4+
5+
Force-support light/dark mode in the front widget

integrations/front/src/script.raw.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,27 @@
55
s = d.createElement('script');
66
s.src = 'https://chat-assets.frontapp.com/v1/chat.bundle.js';
77
s.async = 1;
8-
d.getElementsByTagName('head')[0].appendChild(s);
98

109
s.onload = function () {
1110
if (window.FrontChat) {
1211
window.FrontChat('init', { chatId: chatId, useDefaultLauncher: true });
1312
}
13+
14+
// Workaround for Front's color-scheme bug
15+
// Front's widget uses color-scheme: normal which doesn't respect page color schemes
16+
// This override allows proper light/dark mode support
17+
const styleOverride = d.createElement('style');
18+
styleOverride.textContent = `
19+
[data-front-chat-container],
20+
[data-front-chat-container] iframe,
21+
#front-chat-container,
22+
#front-chat-container iframe {
23+
color-scheme: light dark !important;
24+
}
25+
`;
26+
d.head.appendChild(styleOverride);
1427
};
1528

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

0 commit comments

Comments
 (0)