Skip to content

Commit 374b5ef

Browse files
committed
[chrome] implement getWorkerInjectScripts and cookiedump for IsolatedFrame
1 parent 3593689 commit 374b5ef

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

packages/chrome/src/IsolatedFrame.tsx

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,19 @@ const getInjectScripts: ScramjetInterface["getInjectScripts"] = (
9999
cookieJar,
100100
script
101101
) => {
102-
const dump = JSON.stringify(cookieJar.dump());
103102
const injected = `
104-
self.COOKIE = ${dump};
105-
$scramjetLoadClient().loadAndHook({
106-
interface: {
107-
getInjectScripts: ${getInjectScripts.toString()},
108-
onClientbound: function() { return undefined; },
109-
sendServerbound: async function() {}
110-
},
111-
config: ${JSON.stringify(config)},
112-
transport: null,
113-
});
114-
if ("document" in self && document?.currentScript) {
115-
document.currentScript.remove();
116-
}
117-
`;
103+
$scramjetLoadClient().loadAndHook({
104+
interface: {
105+
getInjectScripts: ${getInjectScripts.toString()},
106+
onClientbound: function() { return undefined; },
107+
sendServerbound: async function() {}
108+
},
109+
config: ${JSON.stringify(config)},
110+
cookies: ${JSON.stringify(cookieJar.dump())},
111+
transport: null,
112+
});
113+
document.currentScript.remove();
114+
`;
118115

119116
// for compatibility purpose
120117
const base64Injected = btoa(
@@ -138,6 +135,26 @@ setInterface({
138135
},
139136
sendClientbound: async (type, msg) => {},
140137
getInjectScripts,
138+
getWorkerInjectScripts: (meta, js, config, type) => {
139+
const module = type === "module";
140+
let str = "";
141+
const script = (script: keyof typeof config.files) => {
142+
if (module) {
143+
str += `import "${config.files[script]}"\n`;
144+
} else {
145+
str += `importScripts("${config.files[script]}");\n`;
146+
}
147+
};
148+
script("wasm");
149+
script("all");
150+
str += `$scramjetLoadClient().loadAndHook({
151+
config: ${JSON.stringify(config)},
152+
interface: {},
153+
transport: null,
154+
});`;
155+
156+
return str;
157+
},
141158
});
142159
export const bare = new BareClient(
143160
new LibcurlClient({

0 commit comments

Comments
 (0)