Skip to content

Commit d70e062

Browse files
authored
Fix the issue with it not properly loading service worker based on if… (#262)
* Fix the issue with it not properly loading service worker based on if it is discord or not. * Styling/Formatting fix * accidently added a b * removed empty new lines * another new line removal
1 parent ed8ee3c commit d70e062

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

platform/web/js/engine/engine.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,19 @@ const Engine = (function () {
241241
*/
242242
installServiceWorker: function () {
243243
if (this.config.serviceWorker && 'serviceWorker' in navigator) {
244-
return navigator.serviceWorker.register(this.config.serviceWorker);
244+
// Check for the two meta elements in the head
245+
const discordAutodetect = document.querySelector('meta[name="discord_autodetect"]')?.content === 'true';
246+
const discordEmbed = document.querySelector('meta[name="discord_embed"]')?.content === 'true';
247+
// Determine the base URL based on the meta elements
248+
let baseUrl = '';
249+
if (discordAutodetect) {
250+
baseUrl = window.location.hostname.includes('discord') ? '.proxy/' : '';
251+
} else if (discordEmbed) {
252+
baseUrl = '.proxy/';
253+
}
254+
// Prepend .proxy/ to the serviceWorker value if needed
255+
const serviceWorkerPath = baseUrl + this.config.serviceWorker;
256+
return navigator.serviceWorker.register(serviceWorkerPath);
245257
}
246258
return Promise.resolve();
247259
},

0 commit comments

Comments
 (0)