gluon: inject IPC on new execution contexts to improve reliability

This commit is contained in:
CanadaHonk 2022-12-13 18:50:32 +00:00
parent d6c4d2769a
commit fc91501918
3 changed files with 7 additions and 3 deletions

View File

@ -39,6 +39,7 @@ export default async ({ browserName, browserPath, dataPath }, { url, windowSize
if (msg.method === 'Runtime.bindingCalled' && msg.name === 'gluonSend') onWindowMessage(JSON.parse(msg.payload));
if (msg.method === 'Page.frameStoppedLoading') pageLoadCallback(msg.params);
if (msg.method === 'Runtime.executionContextCreated') injectIPC(); // ensure IPC injection again
};
let msgId = 0;
@ -117,7 +118,7 @@ export default async ({ browserName, browserPath, dataPath }, { url, windowSize
};
const [ ipcMessageCallback, IPCApi ] = await makeIPCApi({
const [ ipcMessageCallback, injectIPC, IPCApi ] = await makeIPCApi({
browserName,
browserInfo
}, {

View File

@ -111,7 +111,7 @@ user_pref('privacy.window.maxInnerHeight', ${windowSize[1]}); */
name: '_gluonSend'
}); */
const [ ipcMessageCallback, IPCApi ] = await makeIPCApi({
const [ ipcMessageCallback, injectIPC, IPCApi ] = await makeIPCApi({
browserName,
browserInfo
}, {

View File

@ -1,5 +1,6 @@
export default ({ browserName, browserInfo }, { evaluate, addScriptToEvaluateOnNewDocument, pageLoadPromise }) => {
const injection = `(() => {
if (window.Gluon) return;
let onIPCReply = {}, ipcListeners = {};
window.Gluon = {
versions: {
@ -129,7 +130,9 @@ delete window._gluonSend;
sendToWindow('pong', {}, id); // send simple pong to confirm
};
return [ onWindowMessage, {
return [ onWindowMessage, () => evaluate({
expression: injection
}), {
on: (type, cb) => {
if (!ipcListeners[type]) ipcListeners[type] = [];
ipcListeners[type].push(cb);