0

I'm doing a test.It's gonna be constantly passing the updated imageData to the background page and everything runs well,but the data posted will not be imageData.I'm stuck here.

contentscript.js:
var Data=context.getImageData(0,0,canvas.width,canvas.height)
port.postMessage(Data)


background.js:
var Data
chrome.extension.onConnect.addListener(function(port)
{
    port.onMessage.addListener(function(msg) {
        Data=msg
    })
})

The imageData will end up being a object,which is nonsense. Could you please help me? This is what the imageData will be

Chicken
  • 1
  • 1
  • It's [documented](https://developer.chrome.com/extensions/messaging) and you can find many similar answered questions here: the data should be JSON-serializable, which the imageData is not. Convert it to a data url or work with canvas in the background page script. – wOxxOm Aug 06 '16 at 08:26
  • Excuse me, what do you mean to work with canvas in the background page script? – Chicken Aug 06 '16 at 09:46
  • Background page has DOM just like any other web page and you can work with canvas there. – wOxxOm Aug 06 '16 at 09:46
  • Thank you,I'm going to convert the datas to data url now.What if I still want to pass the imageData,then how to make it possible to work with the canvas in the background?The datas will be invalid...... – Chicken Aug 06 '16 at 10:16
  • Well, if your canvas loads an image from the web page and you'd like to do it in a background page, I think you'd have to fetch the image once again with XMLHttpRequest. – wOxxOm Aug 06 '16 at 10:30
  • The imageData is from the video and being brawn with canvas. – Chicken Aug 06 '16 at 10:38
  • http://stackoverflow.com/questions/934012/get-image-data-in-javascript – Haibara Ai Aug 08 '16 at 01:04

0 Answers0