With manifest v2 it is working fine. But with manifest v3 I'm getting error "ReferenceError: localStorage is not defined"
manifest.json
{
"name": "Getting Started Example",
"description": "Build an Extension!",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"permissions": ["storage", "activeTab", "contextMenus"],
"action": {
"default_popup": "popup.html"
}
}
background.js
var contextMenuItems = {
"title": 'Add to notepad"',
"contexts": ["selection"],
"id": "myContextMenuId"
};
chrome.contextMenus.create(contextMenuItems);
chrome.contextMenus.onClicked.addListener(function(clickData){
if(clickData.menuItemId == "myContextMenuId" && clickData.selectionText){
localStorage.setItem("text", "clickData.selectionText");
}
});