4

AngularJS を使用して Chrome パッケージ アプリを作成しています。バックグラウンド スクリプト (「runtime.js」) からプロジェクト内の別の JavaScript ファイルにメッセージを送信しようとしています。

マニフェスト.json

  {
      "name": "App Name",
      "description": "Chrome Packaged",
      "version": "0.0.9",
      "manifest_version": 2,
      "icons": {
        "16": "img/icon16.png",
        "48": "img/icon48.png",
        "128":"img/icon128.png"
      },
      "app": {
        "background": {
          "scripts": ["runtime.js"]
        }
      },
      "permissions": [
        "alarms",
        "storage",
        "unlimitedStorage",
        "notifications",
        "app.runtime"
      ]
    }

ランタイム.js

chrome.app.runtime.onLaunched.addListener(function() {
    chrome.app.window.create('index.html', {
    minWidth: 400,
    minHeight: 700,
    bounds: {
        width: 1000,
        height: 700
    }
    });    
});

chrome.runtime.sendMessage({message: "hello"}, function() {
    console.log('sent')
});

main.js

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    console.log('message received!');
});

バックグラウンド ページを調べると、「ポート: 接続を確立できませんでした。受信側が存在しません。」というエラーが表示され続けます。

何が問題なのかについてのアイデアはありますか? ありがとう!

4

1 に答える 1