Skip to content

Commit

Permalink
feature: allow creating object url in preview script (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
levivilet authored Sep 28, 2024
1 parent 1f95a4b commit fc94ac6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion files/previewInjectedCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@ const handleMessage = async (event) => {

const handleMessageFromTestPort = (event) => {
// TODO invoke test function and send back result
console.log({ event })
const { data, target } = event
const { method, params, id } = data
if (method === 'createObjectUrl') {
const blob = params[0]
const url = URL.createObjectURL(blob)
target.postMessage({
jsonrpc: '2.0',
id,
result: url,
})
} else {
throw new Error('unsupported method')
}
}

const handleWindowMessage = (event) => {
Expand Down

0 comments on commit fc94ac6

Please sign in to comment.