0
Chrome拡張機能から通知を送信できません。コンテンツスクリプトから直接呼び出すことはできないことを認識しています。そのため、background.jsファイルに通知コードがあります。しかし、それはまだ機能していません。 Chrome拡張機能からの通知を表示する方法を理解する上で助けが必要です。コンテンツスクリプトから通知を送信できません
コンテンツスクリプト:
{
"name": "test",
"version": "0.0.1",
"manifest_version": 2,
"description": "xdsfds",
"author": "Miraj",
"background": {
"scripts" : ["background.js"],
"persistent" : false
},
"content_scripts": [
{
"matches": ["https://google.com/*","file:///*/Desktop/extensionPage.html"],
"js": ["/js/lib/jquery-3.1.1.min.js",
"/js/lib/bootstrap.min.js",
"/js/lib/angular.min.js",
"/js/lib/idbstore.js",
"/js/contentScript.js",
"/js/angJs/main.js",
"/js/angJs/communiqueService.js",
"/js/angJs/commTrackerDir.js"],
"css": ["/css/sforce.css",
"/css/main.css"]
}
],
"web_accessible_resources": [
"/templates/*"
],
"permissions": [
"cookies",
"unlimitedStorage",
"notifications"
]
}
Background.js
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
alert('i am listening'); //this is getting invoked
var opt = {
type: "basic",
title: "Primary Title",
message: "Primary message to display",
iconUrl: '/images/notification.png'
};
chrome.notifications.create(new Date().getTime(), opt, function(rs){
alert(rs);
});
sendResponse({returnMsg: "All good!"}); // optional response
});
ContentScript.js
chrome.extension.sendMessage({msg: "Sup?"}, function(response) {
// optional callback - gets response
console.log(response);
});
'extension.onMessage'リスナーの外で通知が発生することを確認しましたか?拡張機能のバックグラウンドページコンソールには何が表示されますか? – Makyen
なぜ 'chrome.extension.onMessage' /' sendMessage'を使用していますか?私は[chrome.runtime.onMessage'](https://developer.chrome.com/extensions/runtime#event-onMessage)を使用することを期待しています。 – Makyen