私はいくつかのフォーム イベント (いくつかの要素をクリックするマウス dbl) をリッスンし、イベントを発生させ、コンテンツ スクリプトでそのイベントをキャッチします。ユーザーが拡張機能を直接操作する必要はありません。ここに私のpage.js(コンテンツスクリプト)があります:
chrome.runtime.sendMessage( { method: e.data.methodName, cid: e.data.cbId, jparams: e.data.jsonParams, objectVersion: e.data.objectVersion, objectFile: e.data.objectFile }, function( response ) {
if( !response ){
//errCallback();
}
} );
現れる:
var host_name = "nativeclientapi";
var messageData = null;
var port = null;
// Listen for messages that come from the content script.
chrome.runtime.onMessage.addListener(
function( request, sender, sendResponse ) {
if( request) {
messageData = request;
alert ('hello');
sendResponse( { res: 'done!' } );
}
} );
マニフェスト:
{
"name": "MyChromeExt.Operarations",
"version": "1.0",
"manifest_version": 2,
"description": "This extension calls a Native API which that API calls some operations.",
"icons": {
"128": "icon.png"
},
"permissions": [
"nativeMessaging", "activeTab"
],
"content_scripts" : [{"matches": ["http://localhost/*","https://localhost/*"], "js": ["page.js"]}]
}
アラートが呼び出されないのはなぜですか? マニフェストにbrowser_actionを追加してポップアップ ページを設定すると機能しますが、拡張機能を操作する必要はありません。
ご協力いただきありがとうございます。