Skip to content

Commit

Permalink
Reduced the scope of the window.postMessage() calls.
Browse files Browse the repository at this point in the history
Improved comments.
  • Loading branch information
FMaz008 committed Jun 28, 2024
1 parent 0b37179 commit d1b17e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
18 changes: 14 additions & 4 deletions scripts/bootloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,9 @@ async function reportfees(event) {
}
}

//Function to receive a message from the website-end and launch an animation
//if the infinite wheel fix was used.
//Messaging from accross tabs and context
//Messages sent via window.postMessage({}, "*");
//Most requests comes from the inj.js file, which is in a different scope/context.
window.addEventListener("message", async function (event) {
//Do not run the extension if ultraviner is running
if (ultraviner) {
Expand Down Expand Up @@ -699,15 +700,21 @@ window.addEventListener("message", async function (event) {
}
}
}
window.postMessage({ type: "variantValidationResponse", result: event.data.variant }, "*");
window.postMessage(
{
type: "variantValidationResponse",
result: event.data.variant,
},
"/" //message should be sent to the same origin as the current document.
);

if (lastResortFixUsed) {
window.postMessage(
{
type: "infiniteWheelFixed",
text: "Last resort method used.",
},
"*"
"/" //message should be sent to the same origin as the current document.
);
}
}
Expand Down Expand Up @@ -851,6 +858,9 @@ window.addEventListener("message", async function (event) {
}
});

//Message from within the context of the extension
//Messages sent via: browser.tabs.sendMessage(tab.id, data);
//In this case, all messages are coming from the service_worker file.
browser.runtime.onMessage.addListener(async function (message, sender, sendResponse) {
let data = message;
if (data.type == undefined) return;
Expand Down
19 changes: 11 additions & 8 deletions scripts/inj.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ window.fetch = async (...args) => {
type: "order",
data,
},
"*"
"/" //message should be sent to the same origin as the current document.
);

//Wait 500ms following an order to allow for the order report query to go through before the redirect happens.
Expand All @@ -71,7 +71,7 @@ window.fetch = async (...args) => {
error: error.exceptionType,
},
},
"*"
"/" //message should be sent to the same origin as the current document.
);
}
return response;
Expand Down Expand Up @@ -101,7 +101,7 @@ window.fetch = async (...args) => {
type: "etv",
data,
},
"*"
"/" //message should be sent to the same origin as the current document.
);
}

Expand Down Expand Up @@ -170,7 +170,7 @@ window.fetch = async (...args) => {
type: "infiniteWheelFixed",
text: fixed + " variation(s) fixed.",
},
"*"
"/" //message should be sent to the same origin as the current document.
);
}

Expand All @@ -193,9 +193,12 @@ async function testVariants(content) {
});

//Send the message to Vine Helper for processing as JQuery is not available in this context
window.postMessage({
type: "variantValidationRequest",
variant: content,
});
window.postMessage(
{
type: "variantValidationRequest",
variant: content,
},
"/" //message should be sent to the same origin as the current document.
);
});
}

0 comments on commit d1b17e4

Please sign in to comment.