2017-06-08 23 views
0

Firefoxのデベロッパー版(バージョン54.0a2を使用していますが、バージョン51の通常のFirefoxを試しました)を使用しており、Web拡張機能に通知を含めたいとします。Web拡張機能(Firefox)で通知が機能しない

ブラウザー["通知"]が存在しません。

私の拡張機能では機能しませんでしたし、何かが矛盾していると思われたので、私はこの非常に基本的なWeb拡張機能を作成しました。

manifest.jsonを:アドオンがdoesn'tいずれかのいずれかのエラーを示してデバッグ

{ 
    "manifest_version": 2, 
    "name": "Extension", 
    "version": "1.0", 

    "description": "...", 

    "icons": { 
    "48": "icons/icon-48.png" 
    }, 

    "content_scripts": [ 
    { 
     "matches": [ 
     "http://*/*", 
     "https://*/*" 
     ], 
     "js": ["test.js"] 
    } 
    ], 
    "permissions": ["notifications", "storage"] 
} 

test.js(記憶ところでだけで正常に動作します。)

if (browser["notifications"]) { 
    console.log('Notifications exist!'); 

    browser.notifications.create({ 
     "type": "basic", 
     "iconUrl": browser.extension.getURL("icons/icon-48.png"), 
     "title": "test", 
     "message": "test" 
    }); 
    } 
    else { 
    //it always executes this part :/ 
    console.log('notifications do not exist'); 
    console.log(browser); 
    } 

+2

あなたはバックグラウンドスクリプトで通知を作成する必要があると思います。ここには簡単な例があります:https://github.com/mdn/webextensions-examples/tree/master/notify-link-clicks-i18n – juvian

+0

ありがとう、それは今動作します! – Michael

答えて

1

拡張機能専用のapisの多くは、バックグラウンドスクリプト内でのみ実行できます。通常、コンテンツスクリプトから実行する必要がある場合は、コンテンツスクリプトからバックグラウンドスクリプトにメッセージを送信し、バックグラウンドスクリプトでメッセージを処理し、そこから必要なコマンドを実行します。

Notification Apiの最後には、notify-link-clicks-i18nという例がいくつかあります。この例では、バックグラウンドスクリプトから通知を作成する方法を確認できます。

関連する問題