最終更新:2014-02-05 (水) 12:13:53 (3732d)  

Google Chrome/拡張機能/コンテントスクリプト
Top / Google Chrome / 拡張機能 / コンテントスクリプト

https://developer.chrome.com/extensions/content_scripts.html

  • 対象ページを表示する際に,そのページのコンテキスト上でJavaScriptを実行
  • サンドボックスみたいな感じで実行される(DOMにはアクセスできるけどJSの関数・変数とかは無理)
  • 表示されたページのDOM操作とか
  • バックグラウンドページとメッセージ通信を行える
     "content_scripts": [
        {
          "matches": ["http://www.google.com/*"],
          "css": ["mystyles.css"],
          "js": ["jquery.js", "myscript.js"]
        }
      ],

できないこと

  • Use chrome.* APIs (except for parts of chrome.extension)
    • メッセージングで間接的に実行可能
  • Use variables or functions defined by their extension's pages
  • Use variables or functions defined by web pages or by other content scripts

manifest.json

  • content_scripts
    • matches
    • css
    • js
    • run_at?
      • document_idle? - デフォルト (document_end?window.onload?)
      • document_start? - DOM構築前 (CSSのロード後)
      • document_end? - DOM構築後 (画像やフレームのロード前)
  • all_frames?
  • include_globs? - matchesの後に適用。
  • exclude_globs?