38
33

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Google Chrome拡張で特定のページで動くJavaScriptを書く

Last updated at Posted at 2015-03-23

http://www.google.com/ でJavaScriptを動かしてみます。

手順

manifest.jsoncontent_scriptsを書く

{
  "name": "Sample",
  "version": "1",
  "manifest_version": 2,
  "description": "This is sample",
  "content_scripts": [{
    "matches": ["https://www.google.co.jp/*"],
    "js": ["script.js"]
  }]
}

matchesでマッチしたサイトでjsで指定したScriptがrun_atのタイミングで実行されます。

script.jsを追加

console.log('hello chorme extension')

Google ChromeでChrome拡張を読み込む

  1. Google Chromeでchrome://extensions/を開く
  2. 右上のデベロッパー モードにチェックを入れる
  3. パッケージ化されていない拡張機能を読み込む...ボタンを押す
  4. manifest.jsonを入れたフォルダを開く

動作確認

Google Chrome で http://www.google.com/ を開いて開発ツールを起動します。

コンソールに次の文字が表示されたら成功です。

hello chorme extension

参考リンク

合わせて読みたい

38
33
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
38
33

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?