Studying extensions for Google Chrome
I get data from a video camera, draw it on canvas
, then get ImageData
from canvas and send it to service_worker
for further processing. As a connection, I use a long-lived port between content and service_worker.
Here is my code:
var port = chrome.runtime.connect({name: 'myPort'}); // <--- opening the port
function run(){
ctx.drawImage(video, 0, 0, 640, 480);
let imageData = ctx.getImageData(0, 0, 640, 480);
let data = Array.from(imageData.data); // <--- 30ms - 40ms
port.postMessage({message: 'video_frame', data: data}); // <--- 40ms - 100ms
};
The main problem is that the sending operation takes a very long time (from 80ms - 140 ms), but at the same time I cannot refuse to send data to service_worker.
Is there a way to speed up data transfer somehow?