Skip to content

Commit

Permalink
Workaround chrome bug with global.ts runtime.onMessage listener
Browse files Browse the repository at this point in the history
- See 2 commits back where I did this but for the event-based-rpc-manager
- This listener shouldn't have been added here in the first place
  • Loading branch information
poltak authored and blackforestboi committed Apr 5, 2024
1 parent 46282a0 commit 8dc58b7
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/content-scripts/content_script/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8dc58b7

Please sign in to comment.