Skip to content

Commit e80b687

Browse files
committed
web: Fix extension does not work in Safari 16 (close #10981)
1 parent 9327d74 commit e80b687

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

web/packages/extension/src/content.ts

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ function injectScriptURL(url: string): Promise<void> {
7878
});
7979
script.charset = "utf-8";
8080
script.src = url;
81+
// safari 16+ script.src will be masked to "webkit-masked-url://hidden/"
82+
script.setAttribute("ruffle-id", String(ID));
8183
(document.head || document.documentElement).append(script);
8284
return promise;
8385
}

web/packages/extension/src/ruffle.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@ function handleMessage(message: Message) {
2828
}
2929

3030
let ID: string | null = null;
31-
if (
32-
document.currentScript !== undefined &&
33-
document.currentScript !== null &&
34-
"src" in document.currentScript &&
35-
document.currentScript.src !== ""
36-
) {
37-
try {
38-
ID = new URL(document.currentScript.src).searchParams.get("id");
39-
} catch (_) {
40-
// ID remains null.
31+
if (document.currentScript !== undefined && document.currentScript !== null) {
32+
if ("src" in document.currentScript && document.currentScript.src !== "") {
33+
try {
34+
ID = new URL(document.currentScript.src).searchParams.get("id");
35+
} catch (_) {
36+
// ID remains null.
37+
}
38+
}
39+
if (ID === null) {
40+
// if `script.src` is masked, get id from attrs
41+
const ruffleId = document.currentScript.getAttribute("ruffle-id");
42+
if (ruffleId) {
43+
ID = ruffleId;
44+
}
4145
}
4246
}
4347

0 commit comments

Comments
 (0)