XKit-Rewritten icon indicating copy to clipboard operation
XKit-Rewritten copied to clipboard

Work around iOS Safari double-content-script bug

Open marcustyphoon opened this issue 4 weeks ago • 1 comments

Description

Not sure if this is only true when it's loaded via the XCode project I made a while ago—god, I hope so—but iOS Safari 18 is, for whatever reason, injecting the XKit Rewritten content script twice.

This is stupid and not something we should have to deal with, and I could see an argument for not cluttering the code with it, but we could make the script throw if a certain property is set on window, then set it, to avoid this occurring and making testing annoying.

(To be clear, I follow a general rule of enthusiastically submitting fixes for iOS Safari even though we currently don't support the platform given that the fixes make semantic sense. In this case, it's a little more, like... the resulting code would, if web standards were followed correctly, obviously do nothing, so I'm not as enthusiastic about it.)

marcustyphoon avatar Nov 29 '25 07:11 marcustyphoon

cheeky... whatever half of a oneliner is:

diff --git a/src/content_scripts/main.js b/src/content_scripts/main.js
index 52b761e9..0495bcbe 100644
--- a/src/content_scripts/main.js
+++ b/src/content_scripts/main.js
@@ -136,6 +136,6 @@
   });
 
   if (redpop) {
-    isReactLoaded() ? init() : waitForReactLoaded().then(init);
+    globalThis.initialized ??= isReactLoaded() ? init() : waitForReactLoaded().then(init);
   }
 }

but I would probably be more explicit :P

marcustyphoon avatar Nov 29 '25 10:11 marcustyphoon