mirror of
https://github.com/ThatNotEasy/PlayReadyProxy.git
synced 2026-04-02 18:48:28 +00:00
31 lines
972 B
JavaScript
31 lines
972 B
JavaScript
async function processMessage(detail) {
|
|
return new Promise((resolve, reject) => {
|
|
chrome.runtime.sendMessage(
|
|
{
|
|
type: detail.type,
|
|
body: detail.body,
|
|
},
|
|
(response) => {
|
|
if (chrome.runtime.lastError) {
|
|
return reject(chrome.runtime.lastError);
|
|
}
|
|
resolve(response);
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
document.addEventListener("response", async (event) => {
|
|
const { detail } = event;
|
|
try {
|
|
const responseData = await processMessage(detail);
|
|
const responseEvent = new CustomEvent("responseReceived", {
|
|
detail: detail.requestId.concat(responseData),
|
|
});
|
|
document.dispatchEvent(responseEvent);
|
|
} catch (error) {
|
|
console.error("Error processing message:", error);
|
|
// Optionally handle the error, maybe notify the user
|
|
}
|
|
});
|