I'm trying to make my own chrome extension for the first time that would capture your active tab as an image and then crop it. As you can see in the code below I used the chrome.tabs.captureVisibleTab() to get the tab as an dataURL. After that I want to convert the dataURL to an Image Object, but the service worker is responding with an Reference Error: Image is not defined.
I'm just confused as to why its not valid? I am using manifest V3, so the script is running as a service worker in the background.
chrome.action.onClicked.addListener(getCurrentTab);
function getCurrentTab(){
let capture = chrome.tabs.captureVisibleTab(null, {}, function(dataUrl){
var img=new Image();
img.src=dataUrl;
});
}
And my manifest.json below if you want to take a look at that
{
"name": "Screen to Text",
"description": "Copies text in selected area to clipboard",
"version": "1.0",
"manifest_version": 3,
"action": {
"select": {
"default_title": "Copy to clipboard",
"default_icon": "icons/copy.png"
}
},
"permissions": ["activeTab", "scripting"],
"background": {
"service_worker": "background.js"
}
}