I want to use SweetAlert for alert box in my chrome extension. SweetAlert has to be shown when clicked in context menu. I have attached the sweetalert code in background scripts property inside manifest.json. I also used the css in content_scripts. Though default alert is showing but SweetAlert is not showing.
Here is the code for manifest.json
{
"manifest_version": 2,
"name": "Detect Sentiment",
"version": "1.0",
"description": "A extension which can detect sentiment",
"icons": {
"128": "icon128.png",
"48": "icon48.png",
"16": "icon16.png"
},
"browser_action": {
"default_icon": "icon16.png",
"default_popup": "popup.html"
},
"background": {
"scripts": ["eventPage.js", "sweetalert.min.js"],
"css": ["sweetalert.css"],
"persistent": true
},
"permissions": ["activeTab", "notifications", "contextMenus"]
}
Here is the code for eventPage.js
var contextMenuItem = {
id: "detectSentiment",
title: "Detect Sentiment",
contexts: ["selection"],
};
chrome.contextMenus.create(contextMenuItem);
chrome.contextMenus.onClicked.addListener(function (clickData) {
if (clickData.menuItemId == "detectSentiment" && clickData.selectionText) {
console.log(clickData.selectionText);
swal("Hello");
alert(clickData.selectionText);
}
});
How can I fix this problem?