LoginSignup
2
1

More than 5 years have passed since last update.

(備忘録)Chrome拡張機能で「Cannot read property 'setBadgeText' of undefined」が出た時の対処法

Posted at

Chromeの拡張機能が作りたくて、いろいろ触っていたのですが、1個詰まってしまったことが解決できたので一応残しておきます。

setBadgeTextは、拡張機能で表示されるここのバッジテキスト。
スクリーンショット 2016-12-18 22.30.05.png

表示の仕方はとても簡単で、「manifest.json」に「background.js」へのアクセスを追加して、jsファイルを作成するだけ。

manifest.json
"background": {
     "scripts": ["background.js"]
}
background.js
chrome.browserAction.setBadgeText({"text":"100"}) // 100個表示

スクリーンショット 2016-12-18 22.33.00.png

だが実行しても、エラー
そんなものは定義されていないと。。。

スクリーンショット 2016-12-18 22.33.42.png

原因は「background.js」は、「browser_action」ありきで、「manifest.json」に下のようなコードを入れないといけなかった。

manifest.json
"browser_action": {
    "default_title": "hoge hoge hoge hoge"
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1