diff --git a/src/content-scripts/content_script/global.ts b/src/content-scripts/content_script/global.ts index cab2ef3171..d6edde3878 100644 --- a/src/content-scripts/content_script/global.ts +++ b/src/content-scripts/content_script/global.ts @@ -269,23 +269,21 @@ export async function main( }, }) - browser.runtime.onMessage.addListener((request, sender) => { + // TODO: This needs to move to an RPC call + browser.runtime.onMessage.addListener(((request, sender, sendResponse) => { if (request.action === 'getImageData') { const imageUrl = request.srcUrl // URL of the image to get data for - return fetch(imageUrl) + fetch(imageUrl) .then((response) => response.blob()) .then((blob) => { - return new Promise((resolve) => { - const reader = new FileReader() - reader.onloadend = () => - resolve({ imageData: reader.result }) - reader.readAsDataURL(blob) // Convert the blob to a data URL - }) + const reader = new FileReader() + reader.onloadend = () => + sendResponse({ imageData: reader.result }) + reader.readAsDataURL(blob) // Convert the blob to a data URL }) - .catch((error) => ({ error: error.toString() })) } - return Promise.resolve() // Return a resolved promise for non-matching actions or to avoid unhandled promise rejections - }) + return true + }) as any) // 3. Creates an instance of the InPageUI manager class to encapsulate // business logic of initialising and hide/showing components.